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

Column Type

2 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 13 Aug 2008, 05:35 PM
I need to get the type of a column in the code behind during the ItemDatabound event.

Column.ColumnType works for getting the string version of a column but not exactly in the way I need it to.

It works for a GridHyperLink column but not Template columns because they are considered GridDataBound columns.

Is there a way to determine if something is a Template column or something without testing for the UniqueName or column index?

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 14 Aug 2008, 05:04 AM
Hi Karl,

You can use directly:
...
if (column is GridTemplateColumn)
{
    //
}
...
Kind regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Princy
Top achievements
Rank 2
answered on 14 Aug 2008, 05:07 AM
Hello Karl,

You can check if a column is GridTemplateColumn or any other column using ColumnType property as shown below.
cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
        { 
            if (col.ColumnType == "GridTemplateColumn") 
            { 
                GridTemplateColumn tempcol = (GridTemplateColumn)col; 
            } 
            else if (col.ColumnType == "GridHyperLinkColumn") 
            { 
                GridHyperLinkColumn hypercol = (GridHyperLinkColumn)col; 
            } 
            else if (col.ColumnType == "GridBoundColumn") 
            { 
                GridBoundColumn boundcol = (GridBoundColumn)col; 
            } 
        } 
     } 

Thanks
Princy.
Tags
Grid
Asked by
Karl
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Princy
Top achievements
Rank 2
Share this question
or