从 asp.net 中的代码隐藏更新 gridview
我的 asp.net 3.5 应用程序 [C#] 中有 gridview。看起来像这样:
<asp:GridView CssClass="grid_table" ID="GridView1" AllowPaging="true" PageSize="10"
AutoGenerateEditButton="true" ShowHeader="true"
AutoGenerateDeleteButton="true" DataKeyNames="studentId" runat="server"
OnRowEditing="GridView1_RowEditing"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDeleting="GridView1_RowDeleting"
OnRowUpdating="GridView1_RowUpdating"
onpageindexchanging="GridView1_PageIndexChanging" onrowupdated="GridView1_RowUpdated"
>
<EmptyDataTemplate>
<asp:Label ID="lblNoRecord" runat="server" Text="No Record Found" ForeColor="Red"> </asp:Label>
</EmptyDataTemplate>
</asp:GridView>
现在,在 rowUpdating 事件中,我正在编写以下代码:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int mytext = Convert.ToInt16(GridView1.Rows[e.RowIndex].Cells[1].Text);
string cConatiner = GridView1.Rows[e.RowIndex].Cells[4].Text;
}
在此, myText 为我提供了正确的值,即第一列的值,但是当我将单元格值更改为 1,2,3,4 时,5,6 我越来越空了。
我做错了吗?
请帮我。
提前致谢。
I have gridview in my asp.net 3.5 application [C#]. Which looks like this:
<asp:GridView CssClass="grid_table" ID="GridView1" AllowPaging="true" PageSize="10"
AutoGenerateEditButton="true" ShowHeader="true"
AutoGenerateDeleteButton="true" DataKeyNames="studentId" runat="server"
OnRowEditing="GridView1_RowEditing"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDeleting="GridView1_RowDeleting"
OnRowUpdating="GridView1_RowUpdating"
onpageindexchanging="GridView1_PageIndexChanging" onrowupdated="GridView1_RowUpdated"
>
<EmptyDataTemplate>
<asp:Label ID="lblNoRecord" runat="server" Text="No Record Found" ForeColor="Red"> </asp:Label>
</EmptyDataTemplate>
</asp:GridView>
Now, In rowUpdating event, I am writing the below code:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int mytext = Convert.ToInt16(GridView1.Rows[e.RowIndex].Cells[1].Text);
string cConatiner = GridView1.Rows[e.RowIndex].Cells[4].Text;
}
In this, myText is giving me the correct value, i.e. of the 1st column but when I am changing the cell value to 1,2,3,4,5,6 I am getting empty.
Am I doing it incorrectly ?
Please help me.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道您在哪里使用 mytext 的值设置单元格的值。我假设您尝试在下面的代码中设置 Cell[4] 的值:
如果 Cell[4] 不是您要设置的单元格,请进行适当更改。
I don't see where you are setting a cell's value with the value of mytext. I am going to assume you are try to set Cell[4]'s value in the code below:
If Cell[4] isn't want cell you're setting, change appropriately.