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

RadGrid Change master table cell BackGround Color

4 Answers 853 Views
Grid
This is a migrated thread and some comments may be shown as answers.
PJ
Top achievements
Rank 1
PJ asked on 18 Jan 2010, 08:12 PM
Hi,

I have a hierarichal grid and I'm trying to change the parent row cell color. The below code is working fine for changing the background color of a cell. But when I click on the expand arrow it is not expanding the detail table. If I comment out this code, it expands fine.

What am I doing wrong? Suggessions please....


protected void RadGridResults_ItemDataBound(object sender, GridItemEventArgs e)
        {
if (e.Item is GridDataItem)
                    {
                        GridDataItem dataItem = (GridDataItem)e.Item;
                        if (dataItem["rpd_cott_ind"].Text == "COTT")
                        {
                            dataItem["rpd_cott_ind"].BackColor = System.Drawing.Color.Brown;
                            dataItem["rpd_cott_ind"].Font.Bold = true;
                        }
                    }
}

Thanks,
PJ.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Jan 2010, 05:44 AM
Hello PJ,

You would have to differentiate between the MasterTableView and the child table using their name properties. Check the following code out and see if it helps in your scenario:
aspx:
<telerik:RadGrid ID="RadGridResults" DataSourceID="SqlDataSource1" runat="server" onitemdatabound="RadGridResults_ItemDataBound">         
   <MasterTableView Name="Master" CommandItemDisplay="Top"  DataSourceID="SqlDataSource1"
       <DetailTables> 
           <telerik:GridTableView Name="Detail" DataSourceID="SqlDataSource2" runat="server"

c#:
 protected void RadGridResults_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name=="Master"
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            if (dataItem["rpd_cott_ind"].Text == "COTT"
            { 
                dataItem["rpd_cott_ind"].BackColor = System.Drawing.Color.Brown; 
                dataItem["rpd_cott_ind"].Font.Bold = true
            } 
        } 
    } 

Thanks
Princy.
0
PJ
Top achievements
Rank 1
answered on 19 Jan 2010, 02:56 PM
Thank you. Your logic is working. I appreciate your help!

After posting the question, I digged into it little bit more and tried this way. Using "foreach" loop resolved the issue too.
                   
                    foreach (GridDataItem dataitem in RadGridResults.MasterTableView.Items)
                    {
                        if (dataItem["rpd_cott_ind"].Text == "COTT")
                        {
                            dataItem["rpd_cott_ind"].BackColor = System.Drawing.Color.Brown;
                            dataItem["rpd_cott_ind"].Font.Bold = true;
                        }
                    }
Thanks,
PJ.

0
Smiely
Top achievements
Rank 1
answered on 12 May 2011, 04:46 PM
Hi, I am using the same logic and it's working for me but I have set BackColor = "Gray" on all the columns. So when it loads the grid it shows Gray color instead of showing the color I set on condition. How can I solve this ?

Smiely
0
Tsvetina
Telerik team
answered on 17 May 2011, 04:28 PM
Hi,

I would advise you to use CSS in order to set styles to your RadGrid control. This way you have more control on how they are applied:
http://www.telerik.com/help/aspnet-ajax/grid-appearance-creating-new-skins.html
http://www.telerik.com/help/aspnet-ajax/grid-appearance-conditional-formatting.html

Best wishes,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
PJ
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
PJ
Top achievements
Rank 1
Smiely
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or