Tim Maxey .NET Technology Blog & Resources

Cool effect for Checkbox List

I was messing around with the checkbox list want simulate a dropdown list with checkboxes in it. A buddy of mine said to try the checkbox list inside a div with scroll bars. Well I did not like the scroll bar on the bottom (horizontal). So I found this:

<div style="width:300px;height:100px;overflow-x: hidden;overflow-y:scroll;overflow:-moz-scrollbars-vertical !important;">
CHECKBOX LIST HERE
</div>

Note the !important is a css hack to tell the browser which tag to use depending upon Firefox or IE.... Cool at any rate, works like a champ... Then when a user "checks" the checkbox for one or more selections, you can stick the list in an update panel and throw this into the SelectedIndexChanged event

       Dim MyItem As ListItem
        For Each MyItem In CheckBoxList1.Items
            If MyItem.Selected = True Then
                MyItem.Attributes.CssStyle.Add("color", "blue")
                MyItem.Attributes.CssStyle.Add("background-color", "yellow")
            End If
        Next

Cool effect, highlights what was "checked...." I even went a step further and added a search box to search the list, but it's too cool to post... Keyword is bubba...


Feedback

# re: Cool effect for Checkbox List

Gravatar How did you search the checkbox list without using SQL statement from a textbox? Thanks... 12/10/2007 9:25 AM | Mike

# re: Cool effect for Checkbox List

Gravatar I used an if statement in the list item for loop and compared the textbox (user inputed string) with a:
If MyItem.Text.ToLower.Contains(TextBox2.Text.Trim.ToLower) = True Then 'do something.... I highlighted the results in the list with blue background... Hope this helps... 12/10/2007 9:28 AM | Timmy

# re: Cool effect for Checkbox List

Gravatar Thanks for your help, as i was searching, how to change the backgrounnd color of the checkboxlist item based on the condition, thanks alot 8/6/2008 11:48 PM | Asim Sajjad

Post a comment





 

Please add 2 and 6 and type the answer here: