2010-05-29 49 views
0

我的asp.net 3.5应用程序[C#]中有gridview。它看起来像这样:从asp.net中的代码更新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列,但是当我正在改变单元格值为1,2,3,4,5,6我变空了。我是不是做得不对?

请帮帮我。

在此先感谢。

+0

请帮忙,我无法找到解决方案 – Zerotoinfinity 2010-05-29 10:13:25

+0

因为我有你的cConatiner总是空的。这是你的问题吗?你检查从DB /(其他来源)获取的数据吗? – chapluck 2010-05-29 10:29:35

+0

我从数据集绑定我的gridview,gridview显示9列和16行,我无法获得单元格的值。 – Zerotoinfinity 2010-05-29 10:34:40

回答

1

我没有看到你正在用mytext的值设置单元格的值。我会假设你正在尝试在下面的代码来设置单元格[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; 
} 

如果细胞[4]是不是想你设置单元格,适当地改变。