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

colored row in grid

1 Answer 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
EdyTeddy-1975
Top achievements
Rank 2
EdyTeddy-1975 asked on 06 Jul 2010, 11:22 AM
Hello, how can i have colored row if item in database is TRUE. for example: all rows with column 'colorStatus'  == true is red and for false, row is green. I speak about background color of row.

thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 06 Jul 2010, 12:13 PM
Hello,

Try the following code snippet to change the background color of grid row based on cell value.

C#:
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if (e.Item is GridDataItem) 
          { 
            GridDataItem item = (GridDataItem)e.Item; 
            if (item["colorStatus"].Text == "True"
              { 
                 item.BackColor = System.Drawing.Color.Red; 
              } 
            else 
                 item.BackColor = System.Drawing.Color.Green;  
           } 
     } 

Also refer the following documentation which explains how to access cells and rows in a grid.
Accessing cells and rows

Thanks,
Princy.
Tags
Grid
Asked by
EdyTeddy-1975
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or