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

4 posts, 1 answers
  1. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 24 Sep 2009 Link to this post

    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.
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Sep 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 25 Sep 2009 Link to this post

    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 
  5. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 25 Sep 2009 Link to this post

    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.
Back to Top