gridhyperlinkcolumn color

5 posts, 0 answers
  1. Ana
    Ana avatar
    40 posts
    Member since:
    Jan 2008

    Posted 06 Apr 2009 Link to this post

    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
  2. Dimo
    Admin
    Dimo avatar
    8330 posts

    Posted 06 Apr 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Des
    Des avatar
    12 posts
    Member since:
    Jan 2009

    Posted 05 Nov 2009 Link to this post

    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
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Nov 2009 Link to this post

    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.
  6. Des
    Des avatar
    12 posts
    Member since:
    Jan 2009

    Posted 05 Nov 2009 Link to this post

    Many thanks Princy, that worked.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017