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

Change Text Color on GridBoundColum

2 Answers 669 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 06 Jul 2009, 10:56 PM

In my grid I have made GridTemplateColumns with labels inside to display text of various colors.  I determine the different color for the text in the code behind of the RadGrid1_ItemDataBound event.  However, I would like to go away from this and just change the forcolor of the text in a GridBoundColumn. 

How can I access the GridBoundColumn from the code behind in the RadGrid1_ItemDataBound event?

This is how I get a labels properties, but I can't get it to work for GridBoundColumns.

 Label time = (Label)e.Item.Cells[0].FindControl("LabelTime"); 

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 Jul 2009, 04:19 AM
Hi Mike,

Try the following code snippet in order to change the ForeColor of gridboundcolumn from code behind.

C#:
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
    { 
        GridDataItem item = (GridDataItem)e.Item; 
        item["ColumnUniqueName"].Style.Add("Color","Red"); 
    } 

-Shinu.
0
Mike
Top achievements
Rank 1
answered on 07 Jul 2009, 12:17 PM
Love it!  Thank you Shinu!
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Share this question
or