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

Set GridDataItem background color server side using CSS

1 Answer 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 11 Jun 2010, 03:19 PM
Hello,

Is it possible to set the background color of specific rows in the RadGrid server side using a style?  I am able to set the background color of the grid rows using the backcolor, but would like to use a style instead as part of validation that a required checkbox on a row is selected.

Thanks,

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 14 Jun 2010, 12:02 PM
Hello Tom,

It is possible to set the background color of a specific row in RadGrid using CSS from code behind. Check out the following code snippet.

CSS:
 <style type="text/css"
 .MyRowClass 
    { 
        background-coloraqua
    } 
 </style> 

ASPX:
  <telerik:GridTemplateColumn> 
        <ItemTemplate> 
            <asp:CheckBox ID="CheckBox1" Checked='<%# Bind("isapproved") %>' runat="server" /> 
        </ItemTemplate> 
   </telerik:GridTemplateColumn> 

C#:
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
       if (e.Item is GridDataItem) 
        { 
          GridDataItem item = (GridDataItem)e.Item; 
          CheckBox chk = (CheckBox)item.FindControl("CheckBox1"); 
            if (chk.Checked) 
            { 
                item.CssClass = "MyRowClass"
            } 
        } 
     } 

You can also refer the following documentation for conditional formatting of grid elements.
Conditional Formatting for rows/cells on ItemDataBound

Regards,
Shinu.





Tags
Grid
Asked by
Tom
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or