gridview编辑无法更新,请大家帮忙
能实现编辑,但点击更新后内容不变,我的代码:protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridView1.DataSource = SqlDataSource2;
GridView1.DataKeyNames = new string[] { "ID" };
GridView1.DataBind();
string str2 = GridView1.DataKeys[e.RowIndex].Values[0].ToString();//获取gridview的主键
string sqlStr = string.Format("update WEBGIS08 set NAME='{0}',SEX='{1}',TELEPHONE='{2}',WORKID='{3}',BIRTHDAY='{4}',QQ='{5}' where ID='{6}'",
((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() ,
((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim(),
((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim(),
((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim(),
((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim(),
((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim(),
str2);
OracleCommand cmd=new OracleCommand (sqlStr ,DBcon .myConn );
DBcon .myConn .Open ();
int rowCount= cmd .ExecuteNonQuery();
DBcon .myConn .Close ();
if (rowCount >0)
{
GridView1 .EditIndex =-1;
string sql1=string .Format ("select * from WEBGIS08");
refreshDgv (sql1 ,true );
}
}
实现编辑的代码:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;//单击一次“编辑”按钮
string sql = string.Format("select * from WEBGIS08");
refreshDgv(sql, true);
}
断点后发现是sqlStr的update语句无法读取编辑后的gridview中的值