简体   繁体   English

更改项目符号列表中列表项目的项目符号样式

[英]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);
     }
}

You can do this with CSS, like this: 您可以使用CSS来执行此操作,如下所示:

li
{
   list-style-type:square;
}

First you'll need to define your css-style: li.active { list-style-type:square; } 首先,您需要定义css样式: li.active { list-style-type:square; } 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);
  }
}

使用c#可以使用以下代码:

BulletedList.Style.Add("list-style-type", "Circle");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM