Solved

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

Posted on 2004-08-10
4
1,646 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
  • 2
  • 2
4 Comments
 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 250 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 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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