Coloring of grid columns

6 posts, 0 answers
  1. Priya
    Priya avatar
    144 posts
    Member since:
    Jul 2008

    Posted 05 Aug 2008 Link to this post

    Sir
    How to give different color to each column of grid

    Thanks
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Aug 2008 Link to this post

    Hi Priya,

    Try the following code snippet to set backcolor of Grid columns depending on their column UniquName.

    CS:
     protected void RadGrid1_PreRender(object sender, EventArgs e) 
        { 
            
            foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
            { 
                if (col.UniqueName == "ProductName") 
                { 
                    col.HeaderStyle.BackColor = System.Drawing.Color.Pink; 
                    col.ItemStyle.BackColor = System.Drawing.Color.Pink; 
                } 
                else if (col.UniqueName == "ProductID") 
                { 
                    col.HeaderStyle.BackColor = System.Drawing.Color.Plum ; 
                    col.ItemStyle.BackColor = System.Drawing.Color.Plum; 
                } 
            } 
        } 


    Thanks
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anil
    Anil avatar
    58 posts
    Member since:
    Nov 2007

    Posted 06 Aug 2008 Link to this post

    Hi Priya,

    Or you can give a different color to the alternate rows using your CSS file.
    For example like in Office2007 skin you can add "background:#C4DDFF;" in GridAltRow_Office2007 td class:-

    .GridAltRow_Office2007 td
    {
        background:#C4DDFF;
        font-family:Arial;
        font-size:11px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    Hope it helps you.

    Thanks
    Anil
  5. Priya
    Priya avatar
    144 posts
    Member since:
    Jul 2008

    Posted 06 Aug 2008 Link to this post

    But when i select the row ,selected row color is not applied in the colored row
  6. Anil
    Anil avatar
    58 posts
    Member since:
    Nov 2007

    Posted 06 Aug 2008 Link to this post

    Hi Priya,

    For selected row you have to modify

    .SelectedRow_Office2007 td,
    .ActiveRow_Office2007 td classes..

    e.g.:-

    .SelectedRow_Office2007 td,
    .ActiveRow_Office2007 td
    {
        background : #A7CDF0;
        font-family:
    Arial;
        font-size:11px;
    }
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Aug 2008 Link to this post

    Hi Priya,

    You can also refer the following help article which explains how to modify existing skin for RadGrid.

    Modifying existing skins/creating new skins
    Customizing row appearance

    Regards
    Princy.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017