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

How to access GridColumn by UniqueName or through the GridDataItem?

3 Answers 1368 Views
Grid
This is a migrated thread and some comments may be shown as answers.
e-statik
Top achievements
Rank 1
e-statik asked on 17 Sep 2008, 01:26 PM
In ItemDataBound i can access cell using gridDataItem["uniquename"]. But how can i access column associated with this cell ? For instance i need to know what DataType the value in my cell is.

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 17 Sep 2008, 01:50 PM
Hello Blokhin

These code-snippets may be helpful:
foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns) 
    if (column.UniqueName == "myUniqueColumnName"
    { 
        string columnType = column.ColumnType; 
        string dataType = column.DataTypeName; 
    } 

protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) 
    if (e.Column.UniqueName == "myUniqueColumnName"
    { 
        string columnType = e.Column.ColumnType; 
        string dataType = e.Column.DataTypeName; 
    } 

string columnType = RadGrid1.MasterTableView.GetColumnSafe("myUniqueColumnName").ColumnType; 
string dataType = RadGrid1.MasterTableView.GetColumnSafe("myUniqueColumnName").DataTypeName; 

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
John
Top achievements
Rank 1
answered on 03 Dec 2015, 01:21 PM
Is it possible to format the data in the column cells?
0
Daniel
Telerik team
answered on 07 Dec 2015, 08:44 AM
Hello John,

Indeed, it is possible thanks to the DataFormatString property.
<telerik:GridBoundColumn DataField="Value" HeaderText="Value" UniqueName="Value"
  SortExpression="Value" DataType="System.Double" DataFormatString="{0:G17}">
</telerik:GridBoundColumn>

More information is available here:
Using columns

Regards,
Daniel
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
e-statik
Top achievements
Rank 1
Answers by
Daniel
Telerik team
John
Top achievements
Rank 1
Share this question
or