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

Change background of specific items

3 Answers 137 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Oscar Emiliano
Top achievements
Rank 1
Oscar Emiliano asked on 08 Aug 2014, 04:16 PM
Hi

I was looking for a way that allow me to change the background color of certain elements. For example, my dropdownlist is showing the name of Users, but I would like to present with a different background those Users that are inactive. With regular asp.net dropdownlist I was able to do this on DataBound method. Is it possible to do something similar with RadDropDownList?

Background color is for the moment my requirement, but of course an answer that allow me to change any css attribute would be even better (font size, color, style, etc).

Thanks in advance of your support
Regards!

Oscar Ramirez

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Aug 2014, 05:11 AM
Hi Oscar,

Below is the sample code snippet to achieve your scenario. I have set one Boolean value for the Active Users and set it as a DataValueField of RadDropDownList. In ItemDataBound event based on the value I am setting the Color and Font-size of a User in the list.

ASPX:
<telerik:RadDropDownList ID="rddlTestDemo" DataSourceID="sqldsUsers" DataTextField="UserName"
    DataValueField="Active" runat="server" OnItemDataBound="rddlTestDemo_ItemDataBound">
</telerik:RadDropDownList>

C#:
protected void rddlTestDemo_ItemDataBound(object sender, Telerik.Web.UI.DropDownListItemEventArgs e)
{
    if (e.Item.Value == "False")
    {
        //inactive user
        e.Item.CssClass = "inactive-user";
    }
    else
    {
        //active user
        e.Item.CssClass = "active-user";
    }
}

CSS:
<style type="text/css">
    .inactive-user
    {
        color :Red !important;
        font-size : medium !important;
    }
    .active-user
    {
        color:Green !important;
        font-size : large !important;
    }
</style>

Thanks,
Shinu.
0
michael
Top achievements
Rank 1
answered on 16 Nov 2017, 09:41 PM

Shinu,

I need to do something similar. My list says "Red" "Green" "Blue" etc.

Is there a way to do that? I tried the following but it did not work.

"dd" is my RadDropdownList

        For i As Integer = 0 To dd.Items.Count - 1

            dd.Items(i).Attributes.Add("style", "color:" + dd.Items(i).Text)
        Next

0
Eyup
Telerik team
answered on 20 Nov 2017, 12:25 PM
Hello Michael,

I've already replied to your query in your formal support ticket about the same matter. I suggest that we continue our technical conversation on the mentioned thread.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
DropDownList
Asked by
Oscar Emiliano
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
michael
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or