2013-11-14 8 views
0

현재 아래 코드를 사용하여 글 머리 기호 목록을 작성하고 있습니다. 그것은 잘 작동하지만 어떤 조건을 충족하는 경우 단일 목록 항목에 대한 글 머리 스타일을 변경할 수 있다면 내가 알고 싶은 것입니다. 이 작업을 수행 할 수 있습니까? 아니면 하나의 목록에있는 모든 글 머리 기호가 동일해야합니까? 어떤 도움을 주셔서 감사합니다.글 머리 기호 목록의 목록 항목에 대한 글 머리 스타일 변경

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

답변

1

먼저 당신은 당신의 CSS 스타일을 정의해야합니다 귀하의 목록 항목을 실제로 귀하의 조건에 따라 필요한 클래스를 얻을 수 있는지 확인하십시오. 당신이 코드 아래 사용할 수 있습니다

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); 
    } 
} 
+0

나는이 알고 CSS로 할 수있는 방법이어야했다. 'Attributes.Add'는 내가 필요한 것입니다. 빠른 응답에 감사드립니다! – ovaltein

2

이 같은 CSS와 함께이 작업을 수행 할 수 있습니다 : 당신이해야합니다, 그 후 li.active { list-style-type:square; }

:

li 
{ 
    list-style-type:square; 
} 
0

사용하여 C 번호 :

BulletedList.Style.Add("list-style-type", "Circle"); 
관련 문제