Tim Maxey .NET Technology Blog & Resources

September 2008 Entries

Update to Highlighted CheckboxList .NET

First, throw this into a Mater Page, or the page you have your CheckBoxList control on... <script type="text/javascript"> function uStyle(cb) { cb.parentNode.style.backgroundColor = cb.checked ? "yellow" : "" ; cb.parentNode.style.color = cb.checked ? "blue" : "" ; } </script> Now I databind the CheckBoxList, so if you do not (you just loaded values manually) then take the the CheckBoxList1.DataBind reference out... I have a Sub I call on the Page Load event: If Not Page.IsPostBack then... "AddScript" Protected Sub AddScript() CheckBoxList1.DataBind         Dim MyItem As ListItem         For Each MyItem In CheckBoxList1.Items             MyItem.Attributes.Add("onclick", "uStyle(this);")         Next     End Sub This seems to work a lot better than having to use an Update Panel and a ONSELECTED_CHANGE event...