protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//调用自定义方法绑定数据到控件
BindData();
}
protected void GV_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//取得编辑行的关键字段的值
string id = this.GV.DataKeys[e.RowIndex].Value.ToString();
//获取文本框中的内容
string Nname = ((TextBox)(this.GV.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string Nsex = ((TextBox)(this.GV.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
string Nage = ((TextBox)(this.GV.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string Naddr = ((TextBox)(this.GV.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
//定义更新操作的SQL语句
string strUpdate = "update tb_user set name='" + Nname + "',sex='" + Nsex + "',age='" + Nage + "',addr='" + Naddr + "' where id='" + id + "'";
SqlCommand com = new SqlCommand(strUpdate, con);
if (Convert.ToInt32(com.ExecuteNonQuery()) > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');location.href='mytest.aspx'</script>");
this.GV.EditIndex = -1;
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!')</script>");
}
解决方案 »
- 'Sys'未定义,其中的一种解决办法跟大家分享一下
- 动态加载控件,控件丢失问题?
- asp.net 无法显示datagrid(在线等,谢谢)
- 急切在线跪求!关于<%=CheckValue()%>问题!
- 调用Com出错?????????????????????
- 有个用flash实现的图片切换效果,要想绑定数据库的内容,该怎么写?
- 关于报表控件的使用问题
- 请问在对数据库进行增加时,access有一字段为日期型的,而获取时是从一textbox获取值,怎么办?
- +++++++++ ASP.NET免费统计图组件更新 ++++++++++++
- 有关静态页面的生成问题后,访问的问题
- asp.net MVC2 的頁面沒有辦法使用EntitySet的方法
- 如何让虚拟目录不继承根目录web.config的设置,vs2005的
if (Convert.ToInt32(com.ExecuteNonQuery()) > 0)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');location.href='mytest.aspx'</script>");
this.GV.EditIndex = -1;
Bind();
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!')</script>");
}
下面加个BindData(); 就OkL