注册 登录
编程论坛 ASP.NET技术论坛

新手求教 GridView 的 RowUpdating 失效?????

c_xiaoxiao 发布于 2011-04-21 21:33, 917 次点击
//我的RowUpdating模块,事件触发都有为啥就是获得不了修改过的数据呢????
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{ string id = GridView1.Datakeys[e.RowIndex].Value.ToString();//能获得行号
string name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();//修改后执行与原数据一样
string local = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();//修改后执行与原数据一样
string sqlStr = "update t_user set fname='"+name+"',flocal='"+local+"' where fid="+id;
SqlConnection myConn = GetConnection();//自定义数据连接方法
myConn.Open();
SqlCommand myCmd = new SqlCommand(sqlStr,myConn);
myCmd.ExecuteNonQuery();
myCmd.Dispose();
myConn.Close();
GridView1.EditIndex = -1;
GridViewBind();//自定义数据绑定页面
}
2 回复
#2
c_xiaoxiao2011-04-24 01:07
擦   没人回答??????????、
#3
懂也不懂2011-04-24 08:59
string sqlStr = "update t_user set fname='"+name+"',flocal='"+local+"' where fid="+id;
应该是string sqlStr = "update t_user set fname='"+name+"',flocal='"+local+"' where fid='"+id+'";
同时你可以在这句之前用response.write()来输出你的各个string看一下获取的结果;同时你在gridview的属性设置”DataKeysName“属性了吧。。
1