protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //调用自定义方法绑定数据到控件
            BindData();
        }
protected void GV_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //取得编辑行的关键字段的值
        string id = this.GV.DataKeys[e.RowIndex].Value.ToString();
        //获取文本框中的内容
        string Nname = ((TextBox)(this.GV.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
        string Nsex = ((TextBox)(this.GV.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
        string Nage = ((TextBox)(this.GV.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
        string Naddr = ((TextBox)(this.GV.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
        //定义更新操作的SQL语句
        string strUpdate = "update tb_user set name='" + Nname + "',sex='" + Nsex + "',age='" + Nage + "',addr='" + Naddr + "' where id='" + id + "'";
        SqlCommand com = new SqlCommand(strUpdate, con);
        if (Convert.ToInt32(com.ExecuteNonQuery()) > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');location.href='mytest.aspx'</script>");
            this.GV.EditIndex = -1;
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!')</script>");
        }

解决方案 »

  1.   

       少写了个Bind()函数
    if (Convert.ToInt32(com.ExecuteNonQuery()) > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');location.href='mytest.aspx'</script>");
                this.GV.EditIndex = -1;
                Bind();
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!')</script>");
            }
      

  2.   

      this.GV.EditIndex = -1;
    下面加个BindData(); 就OkL
      

  3.   

     this.GV.EditIndex = -1;下面 需再绑定一下,  加上  BindData(); 
      

  4.   

    是的,楼主在update后,跳转到mytest.aspx页面,并没有给gridView赋值,所以当然没数据了。