Dear,
I am trying to server-side select a row in a radgrid which is using paging.
In the radgrid prerender I set a griddataitem.selected = true.
This works fine as long as the selected item gets displayed on the current displayed page.
How can i make the radgrid display the page that contains the selected item ?
Kind regards,
N.
5 Answers, 1 is accepted
I guess you want to persist the selection when on paging. If so, you will find the online documentation as a helpful one.
Persisting the selected rows server-side on sorting/paging/filtering/grouping
-Shinu.
Dear,
The thing is that during postback the selection of the grid must be changed at server side.
Kind regards,
N.
I have already addressed the support ticket you have opened on the same topic. For the sake of keeping the support history trackable, let's continue this conversation in the forum thread only. Here is my post from the support ticket:
"Please note that when paging is enabled RadGrid fetches only the data that is required for the items of the currently displayed page. That is why the control does not persist user selection when the displayed page changes. The following help article demonstrates how to work around this behavior:
Persisting the selected rows server-side on sorting/paging/filtering/grouping
An approach similar to the one described in the help topic should be implemented in order to persist the index of the page that has the selected item. Once you know the page index, you can use RadGrid / GridTableView CurrentPageIndex property to navigate to it (you would need to rebind the grid if you set the CurrentPageIndex after the grid is already bound). However note that your "page index persisting" logic should take into account features like sorting or filtering which can cause one item to be contained in a different page when the grid is sorted / filtered."
I hope this helps,
Martin
the Telerik team
private void LoadCurrentItemSelections()
{
List<int> lstSelection = new List<int>();
lstSelection = CurrentItemSelected;
if ((lstSelection != null)
&& (lstSelection.Count > 0)
&& (rgrAssetList.Items.Count > 0))
{
if (CurrentPageIndex > 0)
{
rgrAssetList.CurrentPageIndex = CurrentPageIndex;
rgrAssetList.Rebind();
}
foreach (int iAssetID in lstSelection)
{
try
{
Telerik.Web.UI.GridDataItem gi =
rgrAssetList.MasterTableView.FindItemByKeyValue("AssetId", iAssetID);
if (gi != null)
{
gi.Selected = true;
gi.Focus();
//rgrAssetList.Rebind();
}
}
catch { }
}
}
}
It handles changing the page index if needed also above. It works well in normal aspx pages, but I'm currently having a problem when it's embedded deeper and the scroll bar. I have a page size of 50 per page and the grid height is currently only large enough to show about 12 records at a time. The scroll bar is used to scroll within a page only. When I select an item lower than the top 12 visible in above procedure the scroll bar stays at the top. If I scroll down I can see my item is selected. If I press "tab" key the scroll bar moves to the row selected.
This seems to be a problem when the grid is embedded. This is the structure:
Grid in User Control -> on APSX page -> opened into a RadWindow.
I tried placing this code in the PreRender already and it doesn't resolve. I have this same logic working correctly on other pages in which the RadGrid isn't embedded to this level (it exists directly on ASPX page and not opened by RadWindow).
Anyone else having this problem? More importantly does anyone have a solution?
Thank-you,
Mike
I would suggest that you open a formal support ticket and send me a stripped runnable demo that I could debug locally. This way I would be able to draw a clear picture of your scenario and provide you with more to-the-point resolution.
Regards,
Martin
the Telerik team