Solved

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

Posted on 2004-08-10
4
1,637 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

22 Experts available now in Live!

Get 1:1 Help Now