0

現在、以下のコードを使用して箇条書きリストを埋めています。正常に動作しますが、特定の条件を満たした場合に、単一のリスト項目の箇条書きスタイルを変更できるかどうかを知りたいです。これを行うことはできますか、それとも 1 つのリストのすべての箇条書きを同じにする必要がありますか? どんな助けでも大歓迎です。

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);
     }
}
4

3 に答える 3

1

まず、css スタイルを定義する必要があります。 li.active { list-style-type:square; }

その後、リスト項目が実際に条件に基づいて必要なクラスを取得することを確認する必要があります。

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);
  }
}
于 2013-11-14T14:40:28.887 に答える