Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB.NET version of CheckBoxList Select All Functionality

Posted on 2006-05-21
3
Medium Priority
?
388 Views
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:
=========================================

            <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
0
Comment
Question by:msiedle
3 Comments
 
LVL 39

Accepted Solution

by:
appari earned 1200 total points
ID: 16731641

try changing

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

to

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

Assisted Solution

by:RJeyaPrakash
RJeyaPrakash earned 800 total points
ID: 16731644
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)
{
      checkBox.checked=bCheck;
      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


regards
jp
0
 
LVL 2

Author Comment

by:msiedle
ID: 16733045
Thanks :-) Works great

Mark
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 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