I have a WebDataGrid that has bound columns as well as a TemplateDataField that contains an ImageButton. When you click on the ImageButton, it takes the user to a different page (via the PostBackUrl property) and passes the ID # of that row as a parameter. The parameter passing is handled by the ImageButton.CommandArgument technique.
My query returns hundreds of records. If I use paging on the WebDataGrid and go to Page 2 (or any page other than Page 1), when I click on the button the wrong ID is passed to the new page.
Here's what happens:
On Page 2, if I click the button in the 5th row down ... it returns the ID of the 5th row down from Page 1. Clearly, it's acting like a postback is happening and it loses track that I was actually on Page 2.
One additional detail is that all of the columns in this WebDataGrid are created programatically in the Page_Load event and the ImageButtons are created by first creating a Template Field with a Placeholder in it in the Page_Load event and then creating the ImageButton on the InitializeRow event of the WebDataGrid.
Things work fine when I'm on Page 1 or if I have Paging off.
I could get around this by passing the ID via JavaScript ... but that's an outdate technique I'd rather not use. I'm basically just looking for a good way to pass values to a different ASPX page by clicking on a button in a WebDataGrid. Tried using Session variables and got the same result (wrong ID sent when on Page 2 or greater).
Any suggestions?
Hello John,
if you are using CommandArgument I would suggest you to use Responce.Redirect. Also if you enable paginng on the WebDataGrid you have to keep last page index and set it back to the grid every time you load the page. I made a small sample which stores WebDataGrid's PageIndex and selected ID in session.
Please refer to the attached file and let me know if this is working for you.
Hristo:
Thanks for taking the time to put together the sample. I can see that it works great for your scenario. I'm still having a few issues getting it to work for me in my scenario where the ImageButton is created programatically, but I'll keep playing around with it using your suggested technique.
Hopefully, future versions of the control will make it easier to do such a common thing as pass an ID to another page via a button in a web data grid that uses paging.
Thanks again!