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

    Hello!

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

    http://www.telerik.com/help/aspnet-ajax/grdhideexpandcollapseimageswhennorecords.html

    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)
    AS 
    (
        SELECT 
            ID AS OriginalID
            ,ID
            ,0 AS Children
            ,Name
        FROM [Categories]
    UNION ALL
        SELECT 
            y.OriginalID
            ,s.ID
            ,1 AS Children
            ,y.Name
        FROM [Categories] AS s
        INNER JOIN ExampleDataTable AS y ON y.ID = s.ParentID
    )
    SELECT 
        OriginalID AS ID
        ,Name
        ,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;
                   }
               }
           }



    /M
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top