gridview中commandfield的更新按钮中代码怎么写才能实现数据更新呢(RowUpdating,RowDeleting)
如题 --------------------编程问答-------------------- up --------------------编程问答-------------------- http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.commandfield(VS.80).aspx --------------------编程问答-------------------- 写个简单的table的更新吧protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text.ToString().Trim(); //取textbox控件的值
string name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2")).Text.ToString().Trim();
dt = (DataTable)Session["data"];//这里的session保存的是前面绑定的原始数据
dt.Rows[e.RowIndex]["ID"] = id;
dt.Rows[e.RowIndex]["姓名"] = name;
Session["data"] = dt;//改变session的值
GridView1.EditIndex = -1;
this.BindData();//重新绑定
}
删除表中的数据.只对table操作
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
dt = (DataTable)Session["data"];
int a = Convert.ToInt32(e.RowIndex);
try
{
dt.Rows[a].Delete();
Response.Write(" <script> alert( '数据库操作成功!'); </script> ");
}
catch
{
Response.Write(" <script> alert( '数据库操作失败!'); </script> ");
}
Session["data"] = dt;
BindData();
}
补充:.NET技术 , C#