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

[Solved] Dropdownlist Alternating row colors

1 Answer 45 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Carlyle
Top achievements
Rank 1
Carlyle asked on 24 May 2011, 03:37 PM
I have tried to find an example of how to get alternating rows for my dropdownlist but i'm unable to do so. Can this be down for hmtl dropdownlist?

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 25 May 2011, 06:23 AM
Hello Carlyle,

You can achieve the desired appearance by using the following CSS rule:

.t-popup .t-item:nth-child(2n+1)
{
    background:red;
}

However, this does not work in IE8 and below. If you have to support this browser, then a Javascript approach is required:

Html.Telerik().ComboBox().Name("ComboBox").ClientEvents(ev => ev.OnOpen("applyCss"))


function applyCss(e)
{
    var items = $(this).data("tComboBox").dropDown.$items
    var l = items.length;
    for (var j = 0; j < l; j++)
    {
        if (j % 2 == 1)
          items[j].className += " t-alt";
    }
}

I recommend you to use a flag and execute the handler only once. If you use web service or AJAX binding, you can subsribe to the OnDataBound event instead. By adding the t-alt CSS class, you will use the native alternating backgrounds. Of course, you can use custom styles as well.

Greetings,
Dimo
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
ComboBox
Asked by
Carlyle
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or