?
Solved

ASP.Net/VB.Net/DataList: How to reset all the checkboxes in a datalist

Posted on 2004-08-10
4
Medium Priority
?
1,665 Views
Last Modified: 2008-01-09
I have a web form that contains a datalist. Each cell of the datalist contains a checkbox. It looks something like this:

[ ] Select All
-----------------
[ ] Person A
[ ] Person B
[ ] Person C
[ ] Person D

The CheckBox.Text property gets its name from databinding to a Name field in a database. The checkbox value is unbound. What I intend to do is insert records into a table for each checked box.

When I turn on the Select All checkbox at the top I want all of the other check boxes to be turned on, and vice versa. What is the code for doing this?
0
Comment
Question by:rgrimm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 1000 total points
ID: 11768751
Hi there...
try this.. (with datagrid)
http://www.dotnetjunkies.com/Tutorial/17F2328F-ECB8-478F-A393-3D0E0F024EC0.dcik

Here is a javascript function to achive, select all..

function SelectAll(CheckBoxControl) {

    if (CheckBoxControl.checked == true) {
       
        var i;
       
        for (i=0; i < document.forms[0].elements.length; i++) {
            if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('myDataGrid') > -1)) {
                document.forms[0].elements[i].checked = true;
            }
        }
    }
   
    else {
       
        var i;
       
        for (i=0; i < document.forms[0].elements.length; i++) {
           
            if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('myDataGrid') > -1)) {
               
                document.forms[0].elements[i].checked = false;
            }
        }
    }
}
==================

<HeaderTemplate>
<input type="CheckBox" name="SelectAllCheckBox" onclick="SelectAll(this)">
</HeaderTemplate>

-Baan
0
 
LVL 4

Accepted Solution

by:
rohanpandya earned 1000 total points
ID: 11769771
Hi

  Do following
first set property AutoPostback = true of checkbox associate with selectAll and then write following in code behind

 Private Sub chkSelectall_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSelectall.CheckedChanged
            Dim i
            If chkSelectall.Checked = True Then
                  For i = 0 To dgTest.Items.Count - 1
                        CType(dgTest.Items(i).FindControl("checkbox1"), CheckBox).Checked = True
                  Next
            End If
            If chkSelectall.Checked = False Then
                  For i = 0 To dgTest.Items.Count - 1
                        CType(dgTest.Items(i).FindControl("checkbox1"), CheckBox).Checked = False
                  Next
            End If
      End Sub
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11771908
Hi Rohan,
your idea is good, but because of  "AutoPostback = true " it will need an extra trip to the server. and I guess it is not at all necessary just to check the CheckBoxes. Javascript will work at the client side and will save you from that extra postback
-Baan
0
 
LVL 4

Expert Comment

by:rohanpandya
ID: 11771987
ya it is also work
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

764 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