Wher eis the best place to apply conditional formatting on No Records

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

    Posted 08 Jan 2011 Link to this post

    I have a hierarchy grid and I want the master table to display a different color background if the underlying table has records. What is the best method for applying the formatting?
  2. Mike Nogen
    Mike Nogen avatar
    34 posts
    Member since:
    May 2006

    Posted 08 Jan 2011 Link to this post


    I think that either you go for the soultion that is described in the help section


    And make some minor modifictions to change the color on that specific Item.

    Or you make your datasource (Sql query) to look up and put the number of children for each item in a seperate hidden column and then you can simply handle the change of the color in the ItemDataBind event.

    An example of such SQL query in parent/child relation could be like this.
    WITH ExampleDataTable (OriginalID, ID, Children, Name)
            ID AS OriginalID
            ,0 AS Children
        FROM [Categories]
            ,1 AS Children
        FROM [Categories] AS s
        INNER JOIN ExampleDataTable AS y ON y.ID = s.ParentID
        OriginalID AS ID
        ,SUM(Children) AS NumberOfChildren
    FROM ExampleDataTable
    GROUP BY OriginalID, Name

    And then in the Grid event

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
               //when the Grid is in normal mode   
               if (e.Item is GridDataItem)
                   GridDataItem item = e.Item as GridDataItem;
                   if (item["NumberOfChildren"].Text.Equals("0"))
                       item.BackColor = System.Drawing.Color.Red;

Back to Top