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

[Solved] Setting a row's CssClass OnItemDataBound

2 Answers 276 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jake
Top achievements
Rank 1
Jake asked on 16 Sep 2009, 08:36 PM
I'm trying to add a CssClass to a row in my grid. I use an OnItemDataBound method to do this, with the following code:

    protected void uxGrid_OnItemDataBound(Object sender, GridItemEventArgs e) 
    { 
        if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) 
        { 
            e.Item.CssClass += " foo"; 
        } 
    } 

However, I'm finding that this code REPLACES the class attribute on the row rather than appending to it.

Without the OnItemDataBound event, the generated HTML is:

<tr class="rgRow" id="..."

With the event, I'd expect this:

<tr class="rgRow foo" id="..."

But instead I get this:

<tr class=" foo" id="..."

Note that no classes are added in any settings on my aspx page. (Also note that I've removed other logic from the OnItemDataBound event for clarity - in reality I only want to add the "foo" class when certain conditions are met.)

What am I doing wrong?

Many thanks!

Jake

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 17 Sep 2009, 12:17 PM
Hi Jake,

The observed behavior is expected. Please add both the custom CSS class and the native one (rgRow or rgAltRow), depending on the item's ItemType.


Best wishes,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jake
Top achievements
Rank 1
answered on 17 Sep 2009, 09:02 PM
Thanks Dimo!

I'm a little surprised that this would be by design - I'd understand that the '=' operator would result in this behavior, but the '+=' operator is meant to add to the string, not replace it.

All the same, I'll add the rgRow and rgAltRow classes manually.

Best,

Jake
Tags
Grid
Asked by
Jake
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Jake
Top achievements
Rank 1
Share this question
or