In order to avoid WEAK typing ( i.e. e.Row.Cells[5] ) I have written a helper method to return the index of an Infragistics UltraWebGrid column based upon its caption text.
This is probably best explained via an example:
In this scenario a row in my SOLVENT search results has been clicked. I want to load the solvent id into session and move to the Solvent Edit page.
protected void uwg_Solvents_DblClick(object sender, Infragistics.WebUI.UltraWebGrid.ClickEventArgs e){
if (e.Row != null){
int solventID = globalHelper.getColumnIndex(ref uwg_Solvents,“Solvent ID”);if (solventID >= 0){
Page.Session[globalHelper.SESSION_SOLVENT_ID] = e.Row.Cells[solventID]);Response.Redirect(
globalHelper.PAGE_ADMIN_EDIT_SOLVENTS);}
else
{
globalHelper.DoAlert(“Error as solvent ID could not be found”,this.Page);}
}
}
The HELPER method code is contained in my App Code directory and is called globalHelper. The helper code is:
public static int getColumnIndex(ref Infragistics.WebUI.UltraWebGrid.UltraWebGrid ultraWebGrid, string columnCaption){
//loop through the columns
foreach (Infragistics.WebUI.UltraWebGrid.UltraGridColumn column in ultraWebGrid.Columns.All){
if (column.HasHeader){
if (column.Header.Caption == columnCaption){
return column.Index;}
}
}
return -1;}