GridView控件上编辑的事件,在更新事件?
问题描述:
我想知道我怎么可以访问 GridView控件
?结果的编辑和更新按钮
我的意思是,如果我从 GridView控件的网站点击编辑按钮
,我想从表中得到一些价值。结果
例如:在按钮1
事件
I would like to know how I can access the edit and the update button from GridView
?
I mean, if I click the edit button from the website in the GridView
, I want to get some values from the tables.
For example: the button1
event.
答
您可以利用GridView的RowUpdating事件的。
You could make use of the GridView rowupdating event.
protected void myGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
的 GridViewUpdateEventArgs
包含 NewValues
属性和 OldValues
我经常使用以下方法来取消更新,如果没有实际上已经改变。
I often use the following to cancel the update if nothing has actually been changed.
foreach (DictionaryEntry d in e.NewValues)
{
String oldValue = e.OldValues[d.Key] == null ? "" : e.OldValues[d.Key].ToString();
String newValue = d.Value == null ? "" : d.Value.ToString();
if (oldValue != newValue)
{
return; // -- change detected
}
}
e.Cancel = true; // -- don't execute the update
myGridView.EditIndex = -1;