?
Solved

Hotmail Style - "Select All" checkbox on a asp:checkbox - need little help

Posted on 2004-10-11
5
Medium Priority
?
353 Views
Last Modified: 2008-02-26
Hi,

I have OnClick script running off my asp:checkbox "Select All" that call a javascript function in order to check and uncheck all checkboxes... I got that part working fine,
Now, once I have selected all checkboxes and then uncheck one checkbox further down I want my "Select All" checkbox at the top to be unchecked...  That's part I cant seem to get working.

Here's my javascript so far and also my OnClick event from my asp:checkbox.  Hope to hear from you guys soon, thanks




function select_deselectAll (chkVal, idVal) {
                              var frm = document.forms[0];

                              // Loop through all elements
                              for (i=0; i<frm.length; i++) {

                                    // Look for our Header Template's Checkbox
                                    if (idVal.indexOf ('chxSelectAll') != -1) {

                                          // Check if main checkbox is checked, then select or deselect datagrid checkboxes
                                          if(chkVal == true) {
                                                frm.elements[i].checked = true;
                                          }
                                          else {
                                                frm.elements[i].checked = false;
                                          }
                                    }
                                    
                                    // Work here with the Item Template's multiple checkboxes
                                     else if (idVal.indexOf ('chxSelect') != -1) {
                                          // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
                                          if(frm.elements[i].checked == false) {
                                                //frm.elements[1].checked = false; //Uncheck main select all checkbox
                                                //frm.getElementById('chxSelectAll').checked = false;
                                                alert("uncheck master box");
                                                var myId = document.getElementById("chxSelectAll");
                                                alert(myId);
                                                //myId.checked = false;
                                          }
                                    }
                              }

                        }







<asp:TemplateColumn HeaderText="Workflow">
      <HeaderTemplate>
            <asp:CheckBox id="chxSelectAll" OnClick="javascript: return select_deselectAll(this.checked, this.id);" Text="All" Runat="server" Width="50px"></asp:CheckBox>
      </HeaderTemplate>
      <ItemTemplate>
            <asp:checkbox id="chxSelect" OnClick="javascript: return select_deselectAll(this.checked, this.id);" Runat="server" Width="50px" Visible=False></asp:checkbox>
      </ItemTemplate>
</asp:TemplateColumn>



The bug lies within the last part of my javascript function.

      
0
Comment
Question by:newbreedcc
[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
  • 3
5 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12276598
Hi newbreedcc,

look here : http://forums.devshed.com/archive/t-11535

Regards!
B..M
0
 
LVL 8

Expert Comment

by:tomvergote
ID: 12278303
>  var myId = document.getElementById("chxSelectAll");

if you view source, does it actually get that id?
using controls in web forms might mess up your naming.

you should look into control.clientid.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIControlClassClientIDTopic.asp

"ASP.NET automatically generates a ClientID for a server control regardless of whether you have specified an ID property for it or not. This property is used to identify a control for client-side operations, such as ECMAScript functions."
0
 
LVL 8

Accepted Solution

by:
tomvergote earned 375 total points
ID: 12278330
maybe i should elaborate.

you should add the script in the onload (or other) function by using the RegisterClientScriptBlock method.
The code for the script should be partially dynamically generated (ie the control names should be done as mentioned above).

your code should look like (pseudo code whipped up quickly before dinner)
page. RegisterClientScriptBlock( ....."else if (idVal.indexOf ('chxSelect') != -1) {
                                   // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
                                   if(frm.elements[i].checked == false) {
                                        //frm.elements[1].checked = false; //Uncheck main select all checkbox
                                        //frm.getElementById('chxSelectAll').checked = false;
                                        alert("uncheck master box");
                                        var myId = document.getElementById(\"" + MyCheckBox.ClientID + "\");
                                        alert(myId);
                                        //myId.checked = false;
                                   }");
0
 
LVL 8

Expert Comment

by:tomvergote
ID: 12278342
0
 
LVL 1

Author Comment

by:newbreedcc
ID: 12286717
Hi,

Thank you for the aricle, helped alot.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

777 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