To highlight a particular item in a DropDownList

//The following function describes the code to highlight a particular item in a DropDownList. Here i have assumed that that the

DropDownList name is dlSelectedAction

private void HighLight()

{

foreach (ListItem item in dlSelectAction.Items)

{

if (item.Value.Equals(“the index of the item”))

{

item.Attributes.Add(“class”, “categoryItemStyle”);

//Here you need to create a class in your stylesheet (.css file) that has the name “categoryItemStyle” as shown below.

In that class you can specify the background color of your choice using background-color property.

You can use another class name too.

}

}

}

.categoryItemStyle
{
background-color: red;
}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.