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

RadGrid Change row background color

3 Answers 487 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Srinivas Nilagiri
Top achievements
Rank 1
Srinivas Nilagiri asked on 30 Mar 2011, 11:02 AM
Hi, 
In each row of my RadGrid I have a CheckBox as shown below.
<telerik:GridTemplateColumn HeaderText="Is Critical?" HeaderButtonType="TextButton" UniqueName="critical">
    <ItemTemplate>                                                                   
        <asp:CheckBox ID="chkCritical" runat="server" />
    </ItemTemplate>                                                                
</telerik:GridTemplateColumn>

When the user checks the CheckBox system makes an ajax call from clientside and updates the database. This part is working fine.
I want change the row background color on check/uncheck of the CheckBox on clientside. Could not find a method to set background color on DataItem. Please help.

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 30 Mar 2011, 11:20 AM
Hi Srinivas,

To achieve your goal you can check if the CheckBox is check/uncheck and depending on this you can set different style for the whole row using this code:

eventArgs.get_gridDataItem().get_element().style.backgroundColor = "red";

Greetings,
Pavlina
the Telerik team
0
Srinivas Nilagiri
Top achievements
Rank 1
answered on 31 Mar 2011, 02:48 AM
Thanks Pavlina for the reply. This is working when I don't set a CssClass for the row. On serverside ItemDataBound I am setting CssClass like this if the item is critical.
if (e.Item.ItemType == GridItemType.Item)
{
    item.CssClass = "rgRow critical";                               
}
else
{
   item.CssClass = "rgAltRow critical";                               
}

When I assign backgroundColor as suggested it doesn't change. I tried eventArgs.get_gridDataItem().get_element().CssClass = "rgRow" but not working too. Not sure whether this is right way of doing, the following code works.
if (chk.checked) {
     $(dataitem.get_element()).addClass('criticalspare') ;  
} else {
    $(dataitem.get_element()).removeClass('criticalspare');
}



0
Pavlina
Telerik team
answered on 05 Apr 2011, 12:37 PM
Hi Srinivas,

You can check the forum thread below and see if it helps:
http://www.telerik.com/community/forums/aspnet-ajax/grid/change-row-color-based-on-two-template-check-boxes.aspx

Best wishes,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Srinivas Nilagiri
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Srinivas Nilagiri
Top achievements
Rank 1
Share this question
or