ASP.NET GridView issue
Well I have a gridview where I have defined the columns myself and disabled auto-generation, but now I have a problem that I cannot access the GridView.SelectedRow.DataItem.
As it turns out, it is now null when it mattered when autogeneration was enabled.
Edit: What I need is a way to keep the string id until showing the id to the user, if there is any way to do this?
a source to share
I am assuming the DataItem is only populated when using the DataBinding. Are you using DataBinding?
Well from url :
The GridView (and, in fact, all of our data controls) does not persist these items across postbacks. This reduces the ViewState (if the objects are even serializable) and allows garbage collection and cleanup of objects. So when you click to go back, the GridView has an uncalled DataBind and so your data is not there. This is what you found.
Assuming you are reading the value from the postback, there might be a problem.
Try using SelectedValue if you have customized the (primary) key for the items. I've always used this and it worked. msdn about SelectedValue
a source to share