Link to home
Start Free TrialLog in
Avatar of msiedle
msiedle

asked on

VB.NET version of CheckBoxList Select All Functionality

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:
=========================================

            <script>
                  function CheckAll(pattern, bCheck)
                  {
                        var inps = document.getElementsByTagName("INPUT");
                        var i;
                        for(i=0;i<inps.length;i++)
                        {
                              if(pattern =='' || inps[i].id.indexOf(pattern) >=0)
                                    if(inps[i].onclick!=ReturnFalse)
                                                inps[i].checked = bCheck;
                        }
                        return;
                  }
            </script>      

Cheers,
Mark
ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of msiedle
msiedle

ASKER

Thanks :-) Works great

Mark