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

Styling Items.

1 Answer 22 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Saravanan
Top achievements
Rank 1
Saravanan asked on 26 Mar 2013, 03:15 AM
Hi,

How to give alternate background color to the RadCombobox dropdown list items? 

Thank you,
Saravanan.

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 26 Mar 2013, 04:27 AM
Hi Saravanan,

Please have a look into the sample code I tried at my end. You can attach the OnLoad server side event and based on the index of the item you can give distinct CSS class.

<telerik:RadComboBox ID="RadComboBox" runat="server" OnLoad="RadComboBox_Load">
    <Items>
        <telerik:RadComboBoxItem Text="Audi" />
        <telerik:RadComboBoxItem Text="Ferrari" />
        <telerik:RadComboBoxItem Text="Porsche" />
        <telerik:RadComboBoxItem Text="BMW" />
        <telerik:RadComboBoxItem Text="Toyota" />
        <telerik:RadComboBoxItem Text="Volkswagen" />
    </Items>
</telerik:RadComboBox>

C#:
protected void RadComboBox_Load(object sender, EventArgs e)
{
    foreach (RadComboBoxItem Items in RadComboBox.Items)
    {
        if (Items.Index % 2 == 0)
            Items.CssClass = "comboBoxListItem";
        else
            Items.CssClass = "alternatingComboBoxListItem";
    }
}

CSS:
<style type="text/css">
    .comboBoxListItem
    {
        background-color: #C9F1FA;
    }    
    .alternatingComboBoxListItem
    {
        background-color: #FFF;
    }
</style>

Thanks,
Princy.
Tags
ComboBox
Asked by
Saravanan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or