UltraWebGrid helper to find a column index based on the caption

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.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;}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s