2010-09-07 20 views
0

我正在使用Databind()從數據庫填充的複選框列表。我在UpdatePanel中使用Dropdownlist來避免也是填充表單數據庫的回傳。每個項目在下拉列表中 - >與複選框列表中的多個項目相關聯。有什麼辦法可以使下拉選定索引更改事件的相關列表項目大膽(突出顯示它們),以便用戶知道他必須爲下拉列表中的選定值選擇突出顯示的複選框? 我已經嘗試使用listitem屬性,但它不工作。請參閱下面的代碼。如何更改複選框列表的單個Lineitems字體?

protected void LOSDropDownList_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     try 
     { 
      string selectedValue = LOSDropDownList.SelectedValue; 
      LOSQuestionsBOReadOnlyList QuestionList = LOSQuestionsBOReadOnlyList.GetLOSQuestionsBOReadOnlyListByLevelOfServiceId(Convert.ToInt32(selectedValue));         
      if (!selectedValue.Equals("")) 
      { 
       foreach (ListItem Item in QuestionCheckboxList.Items) 
       { 
        Item.Attributes.CssStyle.Clear(); 
        if(QuestionList.FirstOrDefault(Val => (Val.ServiceLevelQuestion_ID == int.Parse(Item.Value.ToString()))) == null) 
        { 
         Item.Attributes.CssStyle.Add("font-weight", "bold"); 
        } 
        else Item.Attributes.CssStyle.Add("font-weight", "normal"); 
       }     
      } 
     } 
     catch (Exception ex) 
     { 
      ExceptionPolicy.HandleException(ex, "Event_File_Policy"); 
     } 
    } 

您的幫助將不勝感激

感謝和問候,

阿赫亞

回答

0

試試這個:

在下拉列表的SelectedIndexChanged事件:

foreach(ListItem li in chkboxlist.Items) 
{ 
    //If dropdownlist selection matches with chklistbox (or whatever other logic you want) 
    if(li.Text == dropdownlist.SelectedText) 
    { 
    **//Here's how to set it to bold** 
    li.Attributes.CssStyle.Add("font-weight", "bold"); 
    } 
} 
+0

不,它不起作用 – Chetan 2010-09-08 01:53:38

+0

當你這樣做時會發生什麼? – 2010-09-08 04:16:07

+0

謝謝Sidharth,但它沒有改變字體樣式。我用代碼更新了問題在哪裏試圖設置屬性。請建議。 – Chetan 2010-09-08 05:15:20

相關問題