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.
You could make use of the GridView rowupdating event.
protected void myGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
The GridViewUpdateEventArgs
contain properties for NewValues
and 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;
Also if you use a SQLDataSource, it can automatically do it for you if you specify right queries.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.