I have a GridView that is customized by each page that uses it. The issue I am having with this is that I cannot explicitly set what the DataKeys are (since each page will have different ones — and some pages won’t even have one at all).
I know I could create a publicly accessible array that could be changed by each page and set as the DataKeyNames, but that doesn’t work for the case where there are no data keys (can’t use an empty array for DataKeyNames), plus, this is not a preferable way of doing things.
My GridView uses as SqlDataSource. The reason I need the DataKeys is for a DeleteCommand that uses a Text DeleteCommandType (instead of an SP — much prefer it this way) and I need a unique identifier for that row.
When I actually set the PrimaryKey row to be a visible bound field, I can get that key name, but since it is a Guid, I don’t want that.
I am looking for a way to set the DataKeys to the PrimaryKey row (my Guid) without stating which row name that it is. Is there a way to do this? If not, what is a better way of approaching this problem?
Alternatively, you can store the value in a
Hidden fieldand use the hidden field where it is needed.