GridView_RowUpdating取不到新值的解决方法

房子修得再大也是临时住所,只有那个小木匣才是永久的家,所以,屋宽不如心宽,身安不如心安!


protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
sqlcon = new SqlConnection(strCon);
sqlcon.Open();
string bianhao = Convert.ToString(this.GridView1.DataKeys[e.RowIndex].Value);
string beizhu = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString();
string sqlstr = "SQL語句'";
sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcom.ExecuteNonQuery();
sqlcon.Close();
GridView1.EditIndex = -1;
bind();
}

取列的值為原來的,并不是更新后的,原因是因為Page_Load中加載了數據,每次更新后會自動刷新,所以需在Page_Load中判斷一下是否页面回传,再加載,如下


protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bind();
}
}

本文GridView_RowUpdating取不到新值的解决方法到此结束。失败时郁郁寡欢,这是懦夫的表现。小编再次感谢大家对我们的支持!

您可能有感兴趣的文章
ASP.NET中Response.BufferOutput属性的使用技巧

ASP.NET轻量级MVC框架Nancy的基本用法

使用grpcui测试ASP.NET core的gRPC服务

ASP.NET Core中的对象池介绍

.NET集成ORM框架HiSql