Add Textbox Search functionality in Asp.Net CheckBoxList using jQuery

Introduction: In this article I am going to share How to implement searching or filtering functionality in checkboxlist using jQuery i.e. making checkboxlist items searchable. Moreover it will also count total matched items as per search text. 

Add Textbox Search functionality in Asp.Net CheckBoxList using jQuery

Description:  While working on project it was required to show all employees in checkboxlist so that multiple employees can be selected at a time. But there were more than 500 employees.  Selecting some of the employees from the checkboxlist was very difficult. So I decided to add search functionality to checkboxlist so that I can easily search and select the employees as shown in demo image above.

 Implementation: Let’s create a sample page for demonstration purpose.

HTML Source
<html xmlns="">
<head runat="server">
    <script src=""></script>
    <script type="text/javascript">
        function SearchEmployees(txtSearch, cblEmployees) {
            if ($(txtSearch).val() != "") {
                var count = 0;
                $(cblEmployees).children('tbody').children('tr').each(function () {
                    var match = false;
                    $(this).children('td').children('label').each(function () {
                        if ($(this).text().toUpperCase().indexOf($(txtSearch).val().toUpperCase()) > -1)
                            match = true;
                    if (match) {
                    else { $(this).hide(); }
                $('#spnCount').html((count) + ' match');
            else {
                $(cblEmployees).children('tbody').children('tr').each(function () {
    <form id="form1" runat="server">
            <fieldset style="width: 240px">
                <legend>Searchable CheckboxList Example</legend>
                <asp:TextBox ID="txtSearch" runat="server" onkeyup="SearchEmployees(this,'#cblEmployees');"
                    placeholder="Search employee">
                <span id="spnCount"></span>
                <div style="height: 200px; overflow-y: auto; overflow-x: hidden">
                    <asp:CheckBoxList ID="cblEmployees" runat="server" RepeatColumns="1"
                        RepeatDirection="Vertical" Width="240px" ClientIDMode="Static">
                        <asp:ListItem Text="Sahil" Value="1"></asp:ListItem>
                        <asp:ListItem Text="Kabeer" Value="2"></asp:ListItem>
                        <asp:ListItem Text="Arjun" Value="3"></asp:ListItem>
                        <asp:ListItem Text="Aryan" Value="4"></asp:ListItem>
                        <asp:ListItem Text="Ranbeer" Value="5"></asp:ListItem>
                        <asp:ListItem Text="Armaan" Value="6"></asp:ListItem>
                        <asp:ListItem Text="Salmaan" Value="7"></asp:ListItem>
                        <asp:ListItem Text="Amit" Value="8"></asp:ListItem>
                        <asp:ListItem Text="Virat" Value="9"></asp:ListItem>
                        <asp:ListItem Text="Anand" Value="10"></asp:ListItem>


Now over to you:
A blog is nothing without reader's feedback and comments. So please provide your valuable feedback so that i can make this blog better and If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linkedin and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates.
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..