前台编辑以后,始终是提交编辑之前的值,就是下面的t1.Text总是取不到编辑以后的值
   后台代码:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        TextBox t1 = (TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0];
        TextBox t2 = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0];
        SQLHelper sh = new SQLHelper();
        sh.ExecSQL("UPDATE AddressListCategory SET 组名 = '" + t2.Text.Trim() + "' WHERE 组编号 = " + t1.Text);
        AlertInfo("修改成功");
        GridView1.EditIndex = -1;
        Bind();    }前台代码
      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting" CellPadding="3" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" OnRowEditing="GridView1_RowEditing" Width="100%" OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit">
        <Columns>
          <asp:BoundField DataField="组编号" HeaderText="编号" />
          <asp:BoundField DataField="组名" HeaderText="分类名称" />
          <asp:TemplateField ShowHeader="False">
            <EditItemTemplate>
              <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Update"
                Text="更新"></asp:LinkButton>
              <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="取消"></asp:LinkButton>
            </EditItemTemplate>
            <ItemTemplate>
              <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                Text="编辑"></asp:LinkButton>
              <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
                Text="删除" OnClientClick="return confirm('删除后不可恢复,确定删除吗?')"></asp:LinkButton>
            </ItemTemplate>
          </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="White" ForeColor="#000066" />
        <RowStyle ForeColor="#000066" />
        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
      </asp:GridView>

解决方案 »

  1.   

    将GridView控件的DataKeyName属性设为“组编号”,然后protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            TextBox t1 = (TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0];
            int no = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
            TextBox t2 = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0];
            SQLHelper sh = new SQLHelper();
            sh.ExecSQL("UPDATE AddressListCategory SET 组名 = '" + t2.Text.Trim() + "' WHERE 组编号 = " + no.ToString());
            AlertInfo("修改成功");
            GridView1.EditIndex = -1;
            Bind();
        }
      

  2.   

    把后台代码改成如下:
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            String t1 = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text.Trim();
            String t2 = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.Trim();
            SQLHelper sh = new SQLHelper();
            sh.ExecSQL("UPDATE AddressListCategory SET 组名 = '" + t2 + "' WHERE 组编号 = " + t1);
            AlertInfo("修改成功");
            GridView1.EditIndex = -1;
            Bind();    }
      

  3.   

    是不是页面刷新了得不到值?
    protected void Page_Load(object sender, EventArgs e)
    {
    if(!IsPostBack)
    {......}
    }
      

  4.   

    刚刚回答了一个DataGrid的。http://community.csdn.net/Expert/topic/5229/5229737.xml?temp=4.288882E-02