I have tried a few things but I am unable to get the background color to set on a rad ddl. Here is the code I have that doesn't work:
Method 1
If (dr("ACTIVE")) = 0 Then
ddlOperator.Items(ddlOperator.Items.Count - 1).Attributes.Add("style", "BACKGROUND-COLOR: Red")
End If
Method 2
Dim itemData As New DropDownListItem
itemData.Text = dr("NAME").ToString
itemData.Value = dr("BADGE").ToString
If (dr("ACTIVE")) = 0 Then
itemData.Attributes.Add("style", "background-color: red")
end if
5 Answers, 1 is accepted
Thank you for contacting Telerik support.
You can set a custom CSS class to an item and after that use it in a selector for customizing the item layout by the following:
Dim
itemData
As
New
DropDownListItem
itemData.CssClass =
"customCss"
then the CSS could be:
/*normal state*/
.customCss {
background
:
red
;
}
/*hover, selected state*/
.rddlPopup .customCss.rddlItemHovered,
.rddlPopup .customCss.rddlItemSelected {
background
: magenta;
}
We hope this solution will meet your expectations
Regards,
Magdalena
Telerik
I think you misunderstood my question. What I want is when I load the drop down and an item meets a criteria to turn that item red. I don't care about hover or selected. So for example the number represent the items in the ddl and the background color for each item:
ddl items
1 - background color = black
2 - background color = red
3 - background color = black
4 - background color = red
5 - background color = red
If you do not want to change hovered or selected color, simply skip the second part of the CSS code snippet.
You can set to each item different CSS class and use it for different CSS rules.
VB
If
(dr(
"ACTIVE"
)) = 0
Then
itemData.CssClass =
"customClass1"
End
If
CSS
.customClass
1
{
background
:
red
;
}
Regards,
Magdalena
Telerik
That didn't work. Here is my code
For Each dr As DataRow In dt.Rows
Dim itemData As New DropDownListItem
itemData.Text = dr("NAME").ToString
itemData.Value = dr("BADGE").ToString
If (dr("ACTIVE")) = 0 Then
itemData.CssClass = "InactiveEmployees"
End If
ddlOperator.Items.Add(New DropDownListItem(dr("NAME"), dr("BADGE")))
Next
.css
.InactiveEmployees
{
background: red
}
Nevermind, it did work. This is what I did wrong:
'ddlOperator.Items.Add(New DropDownListItem(dr("NAME"), dr("BADGE")))
ddlOperator.Items.Add(itemData)