ovaltein ovaltein - 4 months ago 7
CSS Question

Change bullet style for list items in a bulleted list

I am currently filling a bulleted list using the code below. It works fine but what I'd like to know is if it's possible to change the bullet style for a single list item if it meets some condition. Can this be done or do all the bullets in one list have to be the same? Any help is appreciated.

List<string> EventInfo = new List<string>();

//add list content here

for (int i = 0; i < EventInfo.Count; i++)
{
ListItem stuff = new ListItem();
if (!string.IsNullOrWhiteSpace(EventInfo[i]))
{
stuff.Text = EventInfo[i];
//check if condition is met and change bullet style for this item
BulletedList.Items.Add(stuff);
}
}

Answer

First you'll need to define your css-style: li.active { list-style-type:square; }

After that, you'll need to make sure your list-items actually get the required class based on your condition.

for (int i = 0; i < EventInfo.Count; i++)
{
  ListItem stuff = new ListItem();
  if (!string.IsNullOrWhiteSpace(EventInfo[i]))
  {
    stuff.Text = EventInfo[i];
    //check if condition is met and change bullet style for this item     
    if(condition)
    {
      stuff.Attributes.Add("class", "active");
    }
    BulletedList.Items.Add(stuff);
  }
}