小女子刚开始学编程,今日学习对在gridview中显示的数据进行修改,我点编辑后,所选数据变成文本框,我修改后,点更新按钮,请问更新按钮里面该写什么代码呢,我是学的C#,ASP.NET,等大家帮我忙哟
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow gvr = this.GridView1.Rows[e.RowIndex];
TextBox txt1 = (TextBox)gvr.Cells[1].Controls[0];
TextBox txt2 = (TextBox)gvr.Cells[2].Controls[0];
TextBox txt3 = (TextBox)gvr.Cells[3].Controls[0];
string UpdateStr = "update table set cell1='" + txt1.Text.Trim()
+ "',cell2='" + txt2.Text.Trim()
+ "',cell3='" + txt3.Text.Trim()
+ "' where id=" + this.GridView1.DataKeys[e.RowIndex].Value;
try
{
mycon.myExecuteNonQuery(UpdateStr); //自己写一个方法
Response.Write("<script language='javascript'>alert('修改成功!');</script>");
}
catch (Exception exp)
{
Response.Write("<script language='javascript'>alert('" + exp.Message + "');</script>");
}
finally
{
this.GridView1.EditIndex = -1;
BindData(); //自定义绑定
}
}