Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
WebDataGrid paging issue on TemplateDataField that contains an ImageButton

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?

Parents Reply Children
No Data