[英]Update gridview from code behind in asp.net
我的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时,我变得空了。
我做错了吗?
请帮我。
提前致谢。
我看不到您使用mytext的值在哪里设置单元格的值。 我将假设您尝试在以下代码中设置Cell [4]的值:
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;
GridView1.Rows[e.RowIndex].Cells[4].Text = mytext;
}
如果Cell [4]不需要您要设置的单元格,则进行适当更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.