首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

点击GridView的编辑按钮为什么出现空白页啊

2013-02-03 
点击GridView的编辑按钮为什么出现空白页啊?求救啊 protected void Page_Load(object sender, EventArgs e

点击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
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!')</script>");


        }
[解决办法]
  this.GV.EditIndex = -1;
下面加个BindData(); 就OkL
[解决办法]
 this.GV.EditIndex = -1;下面 需再绑定一下,  加上  BindData(); 
[解决办法]
是的,楼主在update后,跳转到mytest.aspx页面,并没有给gridView赋值,所以当然没数据了。

热点排行