Hello,
Background: I have toolbar, paged grid, and the form (actually user control) to edit records outside the grid. Usual flows are:
1. User clicks on grid row, I fill the form with the selected row data, user see it. He can then edit data and click Save button on toolbar. Data has been saved and grid has been rebinded then.
2. User clicks Add button on the toolbar, I clear the form out. User enters data and clicks Save button on the toolbar. Data has been saved and grid has been rebinded again.
After the grid has been rebinded, I must select the row (which was just edited or added) programmatically using Grid.SelectedIndexes.Add... (first I determine required page index and row index on page of course).
Everything works great unless changed or added row appears within currently selected grid page after rebinding (e.g data is sorted alphabetically in database query, no sorting in the grid itself, and new record may or may not appear in the currently selected grid page after rebind).
What I can: determine required page index from the underlying dataset (which is possible only when there is no sorting in grid abd is just a workaround that I don't like very much, but no other way found in your help/forums, but it's a subject for another discussion).
I.e. I have all information in my code required to set the corresponding page index. The final step left: select required page (knowing it's index) in the server code behind.
I tried to set Grid.CurrentPageIndex in PreRender event handler as well as just after data reload - nothing works for me. It seems that content to render inside the grid has been created before PreRender event so setting CurrentPageIndex doesn't change anything - after request, I see the old page selected despite of the index I'm setting.
Any way to get what I need (i.e. set selected page of paged grid in code behind and see THAT grid page in browser)?
Please note that switching grid paging off is not an acceptable approach for me: having hundreds or thousands records in dataset, it takes too much time to load page when everything is shwon at time.
Or if I rephrase the question: how to select a row in paged grid, which is located on a page which is not currently selected page in the grid, programmatically?
Background: I have toolbar, paged grid, and the form (actually user control) to edit records outside the grid. Usual flows are:
1. User clicks on grid row, I fill the form with the selected row data, user see it. He can then edit data and click Save button on toolbar. Data has been saved and grid has been rebinded then.
2. User clicks Add button on the toolbar, I clear the form out. User enters data and clicks Save button on the toolbar. Data has been saved and grid has been rebinded again.
After the grid has been rebinded, I must select the row (which was just edited or added) programmatically using Grid.SelectedIndexes.Add... (first I determine required page index and row index on page of course).
Everything works great unless changed or added row appears within currently selected grid page after rebinding (e.g data is sorted alphabetically in database query, no sorting in the grid itself, and new record may or may not appear in the currently selected grid page after rebind).
What I can: determine required page index from the underlying dataset (which is possible only when there is no sorting in grid abd is just a workaround that I don't like very much, but no other way found in your help/forums, but it's a subject for another discussion).
I.e. I have all information in my code required to set the corresponding page index. The final step left: select required page (knowing it's index) in the server code behind.
I tried to set Grid.CurrentPageIndex in PreRender event handler as well as just after data reload - nothing works for me. It seems that content to render inside the grid has been created before PreRender event so setting CurrentPageIndex doesn't change anything - after request, I see the old page selected despite of the index I'm setting.
Any way to get what I need (i.e. set selected page of paged grid in code behind and see THAT grid page in browser)?
Please note that switching grid paging off is not an acceptable approach for me: having hundreds or thousands records in dataset, it takes too much time to load page when everything is shwon at time.
Or if I rephrase the question: how to select a row in paged grid, which is located on a page which is not currently selected page in the grid, programmatically?