I am writing a system in which a user must select a project from a list (Datagrid) before doing anything else. To make the system easire for them I am storing their currently selected project in a database table, and want that prjoect to be the default project when they next log in.
I have all of the code working to set and retrieve the selected project, but want the datagrid to be set to the right page and have the default project row selected.
I have tried looping through the DataKeys collection of the datagrid in the DataBound event to find the row that has the matching data key, but it seems that the Datakeys collection only contains the rows for the currently displayed page of data. I have to manually jump to the relevant page before teh default project row is selected. At this point, the default ProjectID has been stored in a Session variable. I do not want to filter the grid to show only the previously selected project, but need to show all projects so they can select a different one if they want.
How do I get the grid to automatically jump to the correct page and select the correct row?
protected void grdProject_DataBound(object sender, EventArgs e)
if (Convert.ToInt32(Session["ProjectID"]) > 0)
//this.grdProject.SelectedIndex = this.grdProject.DataKeys
int iloop = 0;
foreach (DataKey dkProject in this.grdProject.DataKeys)
if (Convert.ToInt32(dkProject.Value) == Convert.ToInt32(Session["ProjectID"]))
grdProject.SelectedIndex = iloop;