日期:2014-05-17  浏览次数:20439 次

点击GridView的编辑按钮为什么出现空白页啊?求救啊
 
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>");
        }

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