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

[Solved] Backcolor of nestedViewTemplate items

2 Answers 146 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Soren Michelsen
Top achievements
Rank 1
Soren Michelsen asked on 10 Oct 2009, 09:03 AM
I have a grid with a nestedViewTemplate that contains a asp:panel with a number of things in it.

The rows in my grid has alternating backColors, white, gray, white, gray, and so on...

What I would like, is to change the backcolor of my panel in the nestedViewTemplate, so that it matches the expanded row that it "lives in".

Anyone?

Jeppe Jespersen
Denmark

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 13 Oct 2009, 07:23 AM
Hello Jeppe Jespersen,

You can try out the following code to set the background color of the panel placed inside a NestedViewTemplate based on the parent row in the grid:
c#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
       if (e.Item is GridNestedViewItem) 
        { 
            GridNestedViewItem nestedview = (GridNestedViewItem)e.Item; 
            Panel pnl = (Panel)nestedview.FindControl("Panel1"); 
            if(nestedview.ParentItem.ItemType == GridItemType.AlternatingItem
                pnl.BackColor = System.Drawing.Color.LightGray; 
            else 
                pnl.BackColor = System.Drawing.Color.Empty; 
        } 
    } 

Thanks
Princy.
0
Soren Michelsen
Top achievements
Rank 1
answered on 13 Oct 2009, 08:25 AM

Well.... i had to use the PreRender event, but that's besides the point.

Most importantly, your example showed me the way. Perfect!!!

Thanks!
Jeppe
Tags
Grid
Asked by
Soren Michelsen
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Soren Michelsen
Top achievements
Rank 1
Share this question
or