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

How to apply conditional formatting in grid if no child records exist

3 Answers 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AkAlan
Top achievements
Rank 2
AkAlan asked on 24 Sep 2009, 09:43 PM
I want to create a nested Grid and would like to be able to apply some formatting for rows in the master table if there are no child records yet created. I assume I need to put code in the ItemCreated event just not sure where to go from there. Any help would be appreciated.

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 25 Sep 2009, 08:09 AM
Hello AkAlan,

I tried the following code in the PreRender event to achieve a scenario as yours. Probably it may help you:
c#:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            if (item.ChildItem.NestedTableViews[0].Items.Count != 0) 
            { 
                item.BackColor = System.Drawing.Color.LightGreen; 
            } 
            else 
            { 
                item.BackColor = System.Drawing.Color.LightPink; 
 
            } 
        } 
    } 
Note: The HierarchyLoadMode property of the mastertableview should be either set to "ServerBind"/"Client" for the above code to work.

Hope this helps..
Princy.
0
AkAlan
Top achievements
Rank 2
answered on 25 Sep 2009, 05:15 PM
Thanks Princy, That worked like a charm. I will repost the code in VB for others.

Imports Telerik.Web.UI  
 
Partial Class MyRadGrid  
    Inherits System.Web.UI.Page  
    Protected Sub RadGrid1_PreRender(ByVal sender As ObjectByVal e As EventArgs) Handles RadGrid1.PreRender  
        For Each item As GridDataItem In RadGrid1.MasterTableView.Items  
            If item.ChildItem.NestedTableViews(0).Items.Count <> 0 Then 
                item.BackColor = System.Drawing.Color.LightGreen  
            Else 
                item.BackColor = System.Drawing.Color.LightPink  
            End If 
        Next 
    End Sub 
 
End Class 
0
AkAlan
Top achievements
Rank 2
answered on 25 Sep 2009, 10:56 PM
Hi Princy, I just wanted to follow up on this post since I discovered something interesting. This solution won't work if your HierarchyLoadMode is set to ServerOnDemand. Thanks again for the help.
Tags
Grid
Asked by
AkAlan
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
AkAlan
Top achievements
Rank 2
Share this question
or