How to solve the problem that GridView_RowUpdating can not get the new value
This article mainly introduces "how to solve the problem that GridView_RowUpdating cannot get a new value". In daily operation, I believe many people have doubts about how to solve the problem that GridView_RowUpdating cannot get a new value. I have consulted all kinds of information and sorted out simple and easy operation methods. I hope to help you answer the question of "how to solve the problem that GridView_RowUpdating cannot get a new value"! Next, please follow the small series to learn together!
The copy code is as follows:
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 statement '";
sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcom.ExecuteNonQuery();
sqlcon.Close();
GridView1.EditIndex = -1;
bind();
}
The column value is the original one, not the updated one. The reason is that Page_Load loads data, which will be refreshed automatically after each update. Therefore, it is necessary to determine whether the page is returned and loaded again in Page_Load, as follows
The copy code is as follows:
protected void Page_Load(object sender, EventArgs e)
{
if (! Page.IsPostBack)
{
bind();
}
}
At this point, the study of "how to solve the problem that GridView_RowUpdating cannot get a new value" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!