Solved

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

Posted on 2004-08-10
4
1,631 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
ya it is also work
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

9 Experts available now in Live!

Get 1:1 Help Now