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.
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.
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.
John, did you figure this out yet? I have the exact same issue where I am creating my WebDataGrid dynamically and using paging. Even with the example given, whenever I switch pages and then click on my image button I end up with the first page key rather than the current page key.
Haven't spent anymore time on this, but the example given does in fact work.
My compromise was to pass my parameters from the ImageButton via the querystring, and then once I've retrieved the parmeters, I clear the querystring.
So for example (I'm a VB coder--sorry this isn't in C#),
WebDataGrid1_InitializeRow (ByVal sender As Object, ByVal e As Infragistics.Web.UI.GridControls.RowEventArgs) Handles WebDataGrid1.InitializeRow
'Retrieve parameters from respective WebDataGrid cellDim strParm1 As String = e.Row.Items(0).TextDim strParm2 As String = e.Row.Items(1).TextDim strParm3 As String = e.Row.Items(2).TextImageButton1.PostBackURL = "DestinationPage.aspx?PARM1=" & strParm1 & "&PARM2=" & strParm2 & "&PARM3=" & strParm3
Then in the Page_Load (of DestinationPage.aspx)
(1) Retriever parmeters from QueryString (Request.QueryString) and store them in Session variables(2) Form.Action = "DestinationPage.aspx"
-- This results in the querystring parmeters being visible the first time DestinationPage.aspx is loaded, but as the user hits buttons on that page or does anything that results in a PostBack, the querystring is clear because of the Form.Action command.
This is not the most elegant solution, but it gets around the paging issue with dynamically created WebDataGrids.