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

gridhyperlinkcolumn color

4 Answers 443 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ana
Top achievements
Rank 1
Ana asked on 06 Apr 2009, 02:02 PM
Hi! I want to change color of text in each grid row, based on a datakey value. It works fine in all columns but for the text in gridHyperLinkColumn. What to do? I have a custom skin defined on the grid, and this is what I do in code behind. Please can you help me?
void GridMyTasks_ItemCreated(object sender, GridItemEventArgs e)  
        {  
            try 
            {  
                if ((e.Item.ItemType == GridItemType.Item) || (e.Item.ItemType == GridItemType.AlternatingItem))  
                {  
                    if (e.Item.DataItem != null)  
                    {  
                        string dueDate = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ActivityDueDate"].ToString().Trim();  
                        if (dueDate != "")  
                        {                              
                            DateTime date = Convert.ToDateTime(dueDate);  
                            if (date<DateTime.Today)  
                            {                                  
                                e.Item.ForeColor = System.Drawing.Color.Red;  
                            }  
                            else if (date < DateTime.Today.AddDays(10))  
                            {                                  
                                e.Item.ForeColor = System.Drawing.Color.Orange;  
                            }  
                        }  
                    }  
                }  
 
            }  
            catch (Exception ex)  
            {  
                ShowLabel(ex);  
            }  
        } 
Thanks,
Ana

4 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 06 Apr 2009, 03:58 PM
Hello Ana,

e.Item.ForeColor sets a color style to the table row element, however, hyperlinks do not inherit color styles from their parents.

Instead of setting ForeColor, you can set custom CSS classe to the RadGrid items and then use CSS rules.

C#

e.Item.CssClass = "AAAA  MyRedClass";

CSS

.RadGrid  .MyRedClass,
.RadGrid  .MyRedClass  a
{
        color: red ;
}

Note that you have to replace AAAA with rgRow or rgAltRow, depending on the item type (Item or AlternatingItem). If you are using RadControls Q3 2008 or older, the CSS classes are:

GridRow_YourSkinName
GridAltRow_YourSkinName


Regards,
Dimo
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Des
Top achievements
Rank 2
answered on 05 Nov 2009, 11:12 AM
Hi Dimo

This solution doesn't appear to work when the DataNavigateUrlFields / DataNavigateUrlFormatString is used.  Have I missed something?  I simply want my hyperlinks in RadGrid to be blue and not black.  I tried the above but although the code can change the colour of normal columns, the Hyperlink and Button columns are unaffected.

Des
0
Princy
Top achievements
Rank 2
answered on 05 Nov 2009, 12:14 PM
Hello Des,

Check out the following example to change the color for hyperlinkcolumns in your grid:
aspx:
<telerik:GridHyperLinkColumn DataTextField="ProductName" DataNavigateUrlFormatString="Default.aspx?ID={0}" Text="Product" 
 DataNavigateUrlFields="ProductID"  UniqueName="HypCol" HeaderText="HypCol" > 
    <ItemStyle CssClass="hyperlink" /> 
</telerik:GridHyperLinkColumn> 

css:
 .hyperlink a 
    { 
       color:blue !important; 
    } 

Thanks
Princy.
0
Des
Top achievements
Rank 2
answered on 05 Nov 2009, 12:44 PM
Many thanks Princy, that worked.
Tags
Grid
Asked by
Ana
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Des
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or