gridview更新无效(在线急等,解决立马给分)
gridview更新无效,
经测试((TextBox)(girdView1.Rows[e.RowIndex].FindControl( "txtAge "))).Text
这条语句取得的总是原数据库中的值,不能获取编辑状态中输入的值,请问是怎么回事,谢啦~~~
SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings[ "sqlstring "].ToString());
string sqlstr = "update [user] set userName= ' "
+ ((TextBox)(girdView1.Rows[e.RowIndex].FindControl( "txtName "))).Text.ToString().Trim() + " ',userAge= ' "
+ ((TextBox)(girdView1.Rows[e.RowIndex].FindControl( "txtAge "))).Text.ToString().Trim() + " ',userSex= ' "
+ ((RadioButtonList)(girdView1.Rows[e.RowIndex].FindControl( "rblSex "))).SelectedValue.ToString().Trim() + " ' where userID= ' "
+ girdView1.DataKeys[e.RowIndex].Value.ToString() + " ' ";
SqlCommand sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
girdView1.EditIndex = -1;
bind();
------解决方案--------------------是不是在pageload里又从数据库取值了?把pageload事件里的代码写在if(!ispostback){}里面试试呢