Use the RowIndex
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = GridView1.Rows[e.RowIndex]; string name = row.Cells[1].Text; string subname = row.Cells[2].Text; }
To get old / new update row values, you can also use GridViewUpdateEventArgs.OldValues and GridViewUpdateEventArgs.NewValues Dictionaries .
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { string oldName = e.OldValues["Name"]; string oldSubname = e.OldValues["SubName"]; string newName = e.NewValues["Name"]; string newSubname = e.NewValues["SubName"]; }
To detect only changed values (not verified) :
var changed = new Dictionary<Object, Object>(); foreach (DictionaryEntry entry in e.NewValues) { if (e.OldValues[entry.Key] != entry.Value) { changed.Add(entry.Key, entry.Value); } }
or with LINQ:
changed = e.NewValues.Cast<DictionaryEntry>() .Where(entry => entry.Value != e.OldValues[entry.Key]) .ToDictionary(entry => entry.Key, entry => entry.Value);
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowupdating.aspx
source share