In our application, we need to be able to return to the page with the grid, and have the grid select the row you were on before you left.
The path I have been approaching this issue from was to store the PageNumber, the ItemIndex and the NumberPerPage whenever you select a row, in session. Then the user could leave the page and when they return I could simply look for those values and set the grid accordingly. This almost worked.
The problem was that one of the things they user could do when away from the page was change data that the grid is showing. For example, my grid lists Locations is sorted by the Location's Trading Name.
If they select the first row in the grid ('ACME'), then leave that page and in another part of the site and change the Trading Name of that location to 'Z-Acme', returning the grid, the wrong row will be selected. Furthermore, it will most likely be on the wrong page.
What I need is a concrete way to store some value, and to have the grid find and select the correct row based on that value.Regardless of where that row is now. No matter what page or item index.
I did this code (hardcoded for now) but this only finds the row if it is in the currently loaded set.
protected void rgLocations_DataBound(object sender, EventArgs e)
{
string SBingo = String.Empty;
for(int i = 0; i < rgLocations.Items.Count; i++)
{
if (rgLocations.Items[i]["Trading_Name"].Text == "Z-Acme")
{
SBingo = "Found it";
}
}
}
This is not ideal for a couple of reasons.
1. As mentioned above it only searches the records currently returned (which might be just 10 records out of a set of 1000s)
2. The search criteria is based on the Trading Name. As two or more locations 'might' have the same Trading Name in my app, this is far from ideal. I'd like this based on the Primary Key ID of each row. Note: the Primary key is not displayed in the grid. Can the RadGrid store but not display the primary key from each row?
What I'd like is some generic function that takes 2 parameters.
SetGrid(ref RadGrid r, int ItemID)
I just pass it the grid I want to set and the item ID of the row I want selected.
This code would need to happen before the grid is bound to the data source I would think. But I'm not sure.
Problem is I can't see how to do this. The RadGrid seems to work in blocks of data that are 'PageSize' in size.
Anyone done something similar? This seems like pretty basic stuff that should be part of the RadGrid. Maybe I'm just missing it.
Brad