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

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

1 Answer 26 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AkAlan
Top achievements
Rank 2
AkAlan asked on 08 Jan 2011, 09:30 PM
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?

1 Answer, 1 is accepted

Sort by
0
Mike Nogen
Top achievements
Rank 1
answered on 09 Jan 2011, 12:50 AM
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
Tags
Grid
Asked by
AkAlan
Top achievements
Rank 2
Answers by
Mike Nogen
Top achievements
Rank 1
Share this question
or