How to change Individual Lineitems fonts for Checkboxlist?
I am using a checkboxlist which I am populating from the database using Databind(). And i am having Dropdownlist in UpdatePanel to avoid postbacks which is also populated form database. Each Item in dropdownlist-> Associated to Many Items in Checkboxlist. Is there any way I can Make Associated listitems bold(to highlight them) on Dropdown Selected Index Changed Event so that user will know he has to select the highlighted checkboxes for the selected value in dropdownlist? I have tried using the listitem Attributes as well but it's not working. See the code below.
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");
}
}
Your help will be apprecia开发者_运维问答ted
Thanks And Regards,
Chetan
Try this:
On the SelectedIndexChanged event of dropdownlist:
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");
}
}
精彩评论