In my GridView I set AllowSorting="true" and obviuously the view gets sorted upon the column clicked. After this event, the select button besides each row references the row displayed before the sorting event and not the actual one.
A method to reference not the index but the data-key when I click the selcet button?
2
Answers
Hum, sorting and a plain good old regular asp.net button dropped into the gridview should work just fine.
So, say this markup:
So, code to load:
And the sort event:
Ok, so that works just fine.
So, now the above edit button with a simple regular button, and a simple regular button click.
When I click on that button, I have this code:
The above correctly outputs the row index, and also correctly outputs the database PK id (hidden in datakeys).
So, I get/see this:
And the debug.prints show this:
So, the simple plain standard button click shows the correct row index, and the PK value via datakeys. Note the use of "namingContainer". This picks up the row you clicked on, and thus lets you dispense with all of the gridview row event mumbo jumbo – which you don’t need nor want to bother with!!!
So, the simple plain standard button click shows the correct row index, and the PK value via data keys. Note the use of "naming Container". This picks up the row you clicked on, and thus lets you dispense with all of the grid view row event mumbo jumbo – which you don’t need nor want to bother with!!!