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

AutoGenerateColumns Get Columns and Names

2 Answers 209 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Igon
Top achievements
Rank 1
Igon asked on 03 Feb 2009, 02:22 PM
Hi,

I have a RadGrid and the AutoGenerateColumns is set to true.
I am setting the DataSource and binding the Grid. Everything is fine and I can see the result.
My columns are not defined on design time. And I  want to operate on the columns in runtime.

The Question is ,  how can I get the colums names. 

If I type RadGrid.Columns.Count  I receive  0 as value.  Is ther a way to get the Names of the columns.


Thanks in advance






2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 03 Feb 2009, 02:38 PM
Hello Igor,

You can either use AutoGeneratedColumns or RenderColumns collections:
string name = RadGrid1.MasterTableView.AutoGeneratedColumns[0].UniqueName; 

Getting familiar with server-side API

Let us know if you need more information.

Best regards,
Daniel
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 03 Feb 2009, 02:41 PM
Hi,

You can access the Columns using its UniqueName property. The UniqueName property for an AutoGeneratedColumn is the same as the DataField for that particular column in the DataBase.
cs:
 
 protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
  
      int index = RadGrid1.MasterTableView.GetColumnSafe("ColumnUniqueName").OrderIndex;  
     
    }  
 

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