VB.NET version of CheckBoxList Select All Functionality

Posted on 2006-05-21
Last Modified: 2011-10-03
Hi all

I have a checkboxlist of items ...and I want to be able to add a 'select all' checkbox above it that works with javascript on the client side ...

I have tried to do this by adding a checkbox and doing the following, but I get an error in the codebehind saying "Operator + is not defined for types String and CheckBoxList" ...any ideas what I'm doing wrong? ..or if anyone has some existing code they use to accomplish the same task client-side?

presentation ASP.NET
            <asp:CheckBox ID="chk_select_all" Runat="server"></asp:CheckBox>
            <asp:CheckBoxList ID="cbl_tables" Runat="server" AutoPostBack=true>

code behind VB.NET
            chk_select_all.Attributes.Add("onclick", "CheckAll('" + cbl_tables + "_',checked);")

The CheckAll javascript is as follows ...added to ASP.NET form:

                  function CheckAll(pattern, bCheck)
                        var inps = document.getElementsByTagName("INPUT");
                        var i;
                              if(pattern =='' || inps[i].id.indexOf(pattern) >=0)
                                                inps[i].checked = bCheck;

Question by:msiedle
    LVL 39

    Accepted Solution


    try changing

    chk_select_all.Attributes.Add("onclick", "CheckAll('" + cbl_tables + "_',checked);")


    chk_select_all.Attributes.Add("onclick", "CheckAll('cbl_tables_',checked);")
    LVL 4

    Assisted Solution

    hai mark

    here is the code for select all functionality

    function CheckAll(chkGroupName, bCheck)
    var chkBoxid;
    var iCount = 0;
    var checkBox;

    chkBoxid = chkGroupName + "_" + iCount;
    while ((checkBox = document.getElementById(chkBoxid)) != null)
          chkBoxid = chkGroupName + "_" + iCount++;

    where chkGroupName is yr checkbox list name and bcheck is either true or false (ie checked or unchecked)

    And call this function onclick of this SelectAll Check box

    LVL 2

    Author Comment

    Thanks :-) Works great


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now