現在、DataGrid の更新機能に問題があります。入力を DataGrid にキャプチャできません。DataGrid を使用して入力をキャプチャする方法はありますか? 情報インターネットのほとんどは、異なる GridView を使用しているためです。
編集済み: これは、更新、編集、および削除機能を備えた DataGrid です。たとえば、データの行を選択して [編集] ボタンを押し、選択した行にデータを入力してから、[更新] ボタンを押して選択した行の情報を更新します。この状況では、編集後に選択した行情報を取得できません。そのため、行データを更新できません。
ここにHTMLのコードがあります
<asp:DataGrid ID="dgRecords" runat="server" Width="100%" DataKeyField="InsitePriceID"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="5"
OnPageIndexChanged="dgRecords_PageIndexChanged" OnSortCommand="dgRecords_SortCommand"
OnDeleteCommand="dgRecords_OnDelete" OnEditCommand="dgRecords_OnEdit" OnUpdateCommand="dgRecords_OnUpdate"
OnCancelCommand="dgRecords_OnCancel">
<AlternatingItemStyle CssClass="Data"></AlternatingItemStyle>
<ItemStyle CssClass="Data"></ItemStyle>
<HeaderStyle CssClass="ColHeader"></HeaderStyle>
<Columns>
<asp:BoundColumn Visible="False" DataField="InsitePriceID"></asp:BoundColumn>
<asp:BoundColumn DataField="ServicePartFrom" HeaderText="No. of Service Part (From)"
SortExpression="ServicePartFrom"></asp:BoundColumn>
<asp:BoundColumn DataField="ServicePartTo" HeaderText="No. of Service Part (To)"
SortExpression="ServicePartTo"></asp:BoundColumn>
<asp:BoundColumn DataField="BaseAmount" HeaderText="% from Base Amount" SortExpression="BaseAmount">
</asp:BoundColumn>
<asp:EditCommandColumn ButtonType="PushButton" CancelText="Cancel" EditText="Edit"
UpdateText="Update"></asp:EditCommandColumn>
<asp:ButtonColumn ButtonType="PushButton" CommandName="Delete" Text="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
<td style="width: 1014px">
<asp:Label ID="lbla" runat="server"></asp:Label>
<asp:Label ID="lblb" runat="server"></asp:Label>
<asp:Label ID="lblc" runat="server"></asp:Label>
</td>
コードビハインド。
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ucWScr.SetValue("Insite Price");
pnlMsg.Visible = false;
BindData("");
}
}
private void BindData(string _sortExpression)
{
clsAdmin obj = new clsAdmin();
int intNoRec = 0;
DataTable tbl = obj.SearchInsitePrice();
}
protected void dgRecords_OnUpdate(object source, DataGridCommandEventArgs e)
{
if (e.CommandName == "Update")
{
string strInsitePriceID = dgRecords.DataKeys[e.Item.ItemIndex].ToString();
//Error start from here
lbla.Text = e.Item.Cells[1].Text;
lblb.Text = e.Item.Cells[2].Text;
lblc.Text = e.Item.Cells[3].Text;
int intServicePartFrm = Int32.Parse(lbla.Text);
int intServicePartTo = Int32.Parse(lblb.Text);
int fltPercentBaseAmt = Int32.Parse(lblc.Text);
//Error ends here
string strUserLogin = CurrentUser.UserLogin.ToString();
DateTime dteNow = DateTime.Now;
if (strInsitePriceID != "")
{
EStatus status = webform.UpdateInsitePrice(strInsitePriceID, intServicePartFrm, intServicePartTo, fltPercentBaseAmt, strUserLogin, dteNow);
if (status != EStatus.Success) throw new Exception("Update failed.");