This is a migrated thread and some comments may be shown as answers.

RadGrid select row from querystring id

3 Answers 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tiago
Top achievements
Rank 1
Tiago asked on 01 Jul 2011, 12:27 PM
Hello,

I want to be able to pass an id through a querystring and select the row corresponding to that id on the grid, and that grid has paging enabled.

The code that i have working is very inefficient because in order to do this on a paged grid, I have to go through all pages, and rebind to have access to the items and see if the one I want to select is that one. I haven't found a better way to do this, does anyone knows if there is a better way to do this?

Ah, and it seems that the selected value of the combobox with the page size is and empty string when I do this instead of showing the actual size.

Thanks in advance!

if (!Page.IsPostBack)
{
    object folderOb = Request.QueryString["Folder"];
    if (folderOb == null) return;
    int folderId = int.Parse(folderOb.ToString());
 
    while (grdFolders.CurrentPageIndex < grdFolders.PageCount)
    {
        foreach (GridDataItem dataItem in grdFolders.Items)
        {
            Folder folder = dataItem.DataItem as Folder;
            if (folder.FolderId == folderId)
            {
                dataItem.Selected = true;
                grdFolderIndex.Rebind();
                return;
            }
        }
        ++grdFolders.CurrentPageIndex;
        grdFolders.Rebind();
    }
}

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Jul 2011, 01:13 PM
Hello Tiago,

If you have enabled paging in your grid, then one option to achieve this is to disable paging and Rebind the grid. After looping through each grid item again enable paging and Rebind the grid.

C#:
RadGrid1.AllowPaging = false;
RadGrid1.Rebind();
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
   //your code here
}
RadGrid1.AllowPaging = true;
RadGrid1.Rebind();

Thanks,
Princy.
0
Tiago
Top achievements
Rank 1
answered on 01 Jul 2011, 01:34 PM
Hello Princy,

Thanks for your quick response, I have thought about that solution, but didn't use it because if the item is not in the first page, it won't show.

I can try to calculate the item page, based on it's index and page size and force it to show that page.

Edit:
I've tried this before the rebind:
RadGrid.CurrentPageIndex = itemIndex / RadGrid.PageSize;


The page is ok, but the item is not selected, and it would be stupid in my opinion to transverse the page to select the item, but probably the only way to go in this solution.
0
Daniel
Telerik team
answered on 06 Jul 2011, 08:50 AM
Hello Tiago,

If you use custom paging, you can build a query to find the item in your database and return a subset of data based on the location of the item. This will require some coding and would be strongly dependent on the type of your database.

Kind regards,
Daniel
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Tiago
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tiago
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or