积极答复者
gridview怎么记录新旧值

问题
-
在datagrid中按了edit的按钮之后,修改某个单元格的数据,那么怎么记录单元格的久值和新值?
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string newName = e.NewValues.Values.ToString();
string oldName = e.OldValues.Values.ToString();Response.Write(string.Format ("<script language=javascript>alert('old {0} new {1}')</script>",
oldName ,newName));
}
上面的e.newValues 和 e.oldValues 好像没用啊!
那要怎么记录新旧值?
答案
-
要记录新旧数值,必须:
1)使用自动生成的字段(启用GridView的AllowEdit=True),或者使用DataBoundField,要不就是<%Bind("字段")%>放于自定义的TemplateField模板内。
2)同时NewValues和OldValues是IDictionary集合。你应该通过索引器获取:
string newName = e.NewValues.Values["字段名"].ToString(); string oldName = e.OldValues.Values["字段名"].ToString();
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats- 已标记为答案 Song TianModerator 2013年3月8日 9:24
全部回复
-
要记录新旧数值,必须:
1)使用自动生成的字段(启用GridView的AllowEdit=True),或者使用DataBoundField,要不就是<%Bind("字段")%>放于自定义的TemplateField模板内。
2)同时NewValues和OldValues是IDictionary集合。你应该通过索引器获取:
string newName = e.NewValues.Values["字段名"].ToString(); string oldName = e.OldValues.Values["字段名"].ToString();
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats- 已标记为答案 Song TianModerator 2013年3月8日 9:24
-
您的方法好像不行啊??能不能再详细一点,才刚刚学asp.net,麻烦了
你全部的代码,谢谢!(aspx和cs)。If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats