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

Dynamically formatting columns RadGrid1_ColumnCreated

3 Answers 100 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 02 Feb 2012, 04:31 PM
i have a datagrid. i used to use autogeneratecolumns  = true

on the RadGrid1_ColumnCreated
i formatted the columns based upon the datatype (HorizontalAlign, $ formatting, ect)

to get the google-like filtering, i had to go away from that and do a foreach statement to load the columns..

none of the events i have hooked up to seem to help me format it.

if autogeneratecolumns   = false

what event do i hook up to?

3 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 02 Feb 2012, 10:23 PM
Jon:

According to the Using Columns documentation page:

You can customize the properties of auto-generated columns at runtime by providing a handler for the grid's ColumnCreated event. In the event handler, cast the column to the appropriate type and set its attributes.  See the code snippet provided.

And, this approach is ratified in the RadGrid Column Formatting Question forum thread.

Perhaps you should post your entire code so we can better see what is wrong.

Regards,
0
Jon
Top achievements
Rank 1
answered on 02 Feb 2012, 10:26 PM
I am not using autogeneratecolumns   = true

so RadGrid1_ColumnCreated will never fire
0
Princy
Top achievements
Rank 2
answered on 03 Feb 2012, 05:02 AM
Hello,

You can try to format the column in ItemDataBound event. Here is the sample code.
C#:
protected void radgrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
 {
  if (e.Item is GridDataItem)
   {
    GridDataItem dataItem = e.Item as GridDataItem;
    dataItem["EmployeeID"].Style["Color"] = "Red";
   }
 }

Thanks,
Princy.
Tags
General Discussions
Asked by
Jon
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Jon
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or