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

[Solved] URGENT : Dynamically change header backcolor and forecolor

5 Answers 218 Views
Grid
This is a migrated thread and some comments may be shown as answers.
maha
Top achievements
Rank 1
maha asked on 16 Jun 2008, 03:17 PM
I want to change the grid BackColor and Forecolor based on user log in.

I tried to change the header style CSSClass property dynamically, but with no effect.

Can someone help.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Jun 2008, 05:55 AM
Hi Maha,

Try the following  code snippet.

CS:
public static string user; 
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        if (user == "Admin") 
        { 
            RadGrid1.BackColor = System.Drawing.Color.Red; 
        } 
        else 
            RadGrid1.BackColor = System.Drawing.Color.LightBlue; 
 
     } 


Thanks
Shinu.
0
Dimo
Telerik team
answered on 17 Jun 2008, 11:02 AM
Hi,

Please note that setting a new color and background color to RadGrid does not guarantee that they will become visible. This is because there are background colors and images set to the table rows, which are on top of the RadGrid container <div>.

The new color may not become visible for similar reasons.

After all, it depends on the skin, so let us know if you have any troubles and we will tell you how to proceed.


Best wishes,
Dimo
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
maha
Top achievements
Rank 1
answered on 17 Jun 2008, 01:56 PM
Looks like the CSS class is overridden by the Grid's Skin

<

telerik:RadGrid ID="grdPosition1" runat="server" Font-Names="Arial" OnItemCreated="grdPosition1_ItemCreated"

OnItemCommand="grdPosition1_ItemCommand" AllowPaging="True" PageSize="100" OnNeedDataSource="grdPosition1_NeedDataSource"

Font-Size="8pt" GridLines="None" AutoGenerateColumns="False" OnItemDataBound="grdPosition1_ItemDataBound"

ShowFooter="true" OnPageIndexChanged="grdPosition1_PageIndexChanged" OnExcelMLExportRowCreated="grdPosition1_ExcelMLExportRowCreated"

OnExcelMLExportStylesCreated="grdPosition1_ExcelMLExportStylesCreated" Skin="Web20">

Even if i don't specify any skin it is getting the default skin and my CSSClass has no effect on the grid 's header color.

So i have set the header using the SetRenderMethodDelegate.

But i have dynamic columns too, so instead of so much of coding...is there any other way we could override the Grid's header CSS Class.

Thanks in advance.

0
Accepted
Dimo
Telerik team
answered on 17 Jun 2008, 03:51 PM
Hello,

If the styles defined by the custom CSS class are overridden by the skin, then please refer to the following blog post, which explains why this happens and how to avoid this:

How To Override Styles in a RadControl for ASP.NET AJAX Embedded Skin

Basically, if you are setting a custom CSS class to the header cells, you should use the following CSS rule to define custom styles:

div.RadGrid_Web20  .MyCustomHeaderClass
{
    
}

Let us know if you still have troubles with that.


Sincerely yours,
Dimo
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
maha
Top achievements
Rank 1
answered on 17 Jun 2008, 04:41 PM
Awesome.
It worked perfectly.

Thank you so much.
Tags
Grid
Asked by
maha
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Dimo
Telerik team
maha
Top achievements
Rank 1
Share this question
or