Getting column name in GridViewUpdateEventArgs (C#/ASP.NET)
I'm currently trying to come up with a simple solution for the auditing of GridView modification, and have decided to handle the GridViewUpdateEventArgs event to get the column name, old value, and new value. I have the following code:
for (int i = 0; i < e.NewValues.Count; i++)
{
if (e.OldValues[i].ToString() != e.NewValues[i].ToString())
{
sb.Append(e.Keys[i] + ": " + e.OldValues[i] + " => " + e开发者_Go百科.NewValues[i]);
}
}
It works great, except that the e.Keys[i] is giving me the primary key of the row, which isn't what I want - I just want the name of the column. Is this easy to do?
you can use
GridViewColumn col = (GridViewColumn )GridView1.Columns[e.RowIndex];
var name = col.Name
Check out
http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx
Just saying I've worked around it by looping through each key in the OldValues, and creating a list which I can access via a index.
精彩评论