Solved

Check all checkboxes in a treeview

Posted on 2006-07-24
5
946 Views
Last Modified: 2009-07-29
In my ASP.Net 2.0 C# application, I have a page with two treeviews.
Each node of the treeviews has a checkbox.

I need a method of checking/unchecking all of the checkboxes
on the individual treeviews.  Can I do this in Javascript?

Thanks.
0
Comment
Question by:JeffDrummond
  • 3
  • 2
5 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 17167296
Go to browser and copy the complette page html source with both treeviews here as text.

0
 

Author Comment

by:JeffDrummond
ID: 17167435
The page is quite large.  This is the portion inculding the two treeviews, Regions and Categories.  Thanks!

 <table width="350">
                        <tr>
                            <td valign="top">
                                Regions:&nbsp;</td><td>Categories:</td>
                        </tr>
                        <tr>
                            <td align="left" valign="top">
                                <a href="#ctl00_Body_RegionsTreeview_SkipLink"><img alt="Skip Navigation Links." src="/WebResource.axd?d=-ZmMyGfj3hopVa_HZUpeJg2&amp;t=632883495870637959" width="0" height="0" style="border-width:0px;" /></a><div id="ctl00_Body_RegionsTreeview">
      <table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX2SfMWA3mIjcL_y6D_rPDZQ1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn0CheckBox" id="ctl00_Body_RegionsTreeviewn0CheckBox" checked="checked" title="Asia" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sAsia')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt0');" id="ctl00_Body_RegionsTreeviewt0">Asia</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn1CheckBox" id="ctl00_Body_RegionsTreeviewn1CheckBox" title="Africa" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sAfrica')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt1');" id="ctl00_Body_RegionsTreeviewt1">Africa</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn2CheckBox" id="ctl00_Body_RegionsTreeviewn2CheckBox" checked="checked" title="North America" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sNorth America')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt2');" id="ctl00_Body_RegionsTreeviewt2">North America</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn3CheckBox" id="ctl00_Body_RegionsTreeviewn3CheckBox" title="South America" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sSouth America')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt3');" id="ctl00_Body_RegionsTreeviewt3">South America</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn4CheckBox" id="ctl00_Body_RegionsTreeviewn4CheckBox" title="Europe" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sEurope')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt4');" id="ctl00_Body_RegionsTreeviewt4">Europe</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX4iascjIf74mJB0-PvYVJWk1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn5CheckBox" id="ctl00_Body_RegionsTreeviewn5CheckBox" title="Australia" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sAustralia')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt5');" id="ctl00_Body_RegionsTreeviewt5">Australia</a></td>
            </tr>
      </table>
</div><a id="ctl00_Body_RegionsTreeview_SkipLink"></a>
                            </td>
                            <td align="left" valign="top">
                                <a href="#ctl00_Body_CategoriesTreeView_SkipLink"><img alt="Skip Navigation Links." src="/WebResource.axd?d=-ZmMyGfj3hopVa_HZUpeJg2&amp;t=632883495870637959" width="0" height="0" style="border-width:0px;" /></a><div id="ctl00_Body_CategoriesTreeView">
      <table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX2SfMWA3mIjcL_y6D_rPDZQ1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn0CheckBox" id="ctl00_Body_CategoriesTreeViewn0CheckBox" title="Prayer" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s1')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt0');" id="ctl00_Body_CategoriesTreeViewt0">Prayer</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><a id="ctl00_Body_CategoriesTreeViewn1" href="javascript:TreeView_ToggleNode(ctl00_Body_CategoriesTreeView_Data,1,ctl00_Body_CategoriesTreeViewn1,'t',ctl00_Body_CategoriesTreeViewn1Nodes)"><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzXwJx33l_NPW57t40m7ht-9kLit0N6NM4XuHy2GC36lIn0&amp;t=632883495870637959" alt="Collapse Volunteer" style="border-width:0;" /></a></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn1CheckBox" id="ctl00_Body_CategoriesTreeViewn1CheckBox" checked="checked" title="Volunteer" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s2')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt1');" id="ctl00_Body_CategoriesTreeViewt1">Volunteer</a></td>
            </tr>
      </table><div id="ctl00_Body_CategoriesTreeViewn1Nodes" style="display:block;">
            <table cellpadding="0" cellspacing="0" style="border-width:0;">
                  <tr>
                        <td><div style="width:20px;height:1px"><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzXwq8Ng0NpL3MLUVHpxHvn5E1&amp;t=632883495870637959" alt="" /></div></td><td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn2CheckBox" id="ctl00_Body_CategoriesTreeViewn2CheckBox" title="Volunteer SubCat 1" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s2\\6')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt2');" id="ctl00_Body_CategoriesTreeViewt2">Volunteer SubCat 1</a></td>
                  </tr>
            </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
                  <tr>
                        <td><div style="width:20px;height:1px"><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzXwq8Ng0NpL3MLUVHpxHvn5E1&amp;t=632883495870637959" alt="" /></div></td><td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX4iascjIf74mJB0-PvYVJWk1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn3CheckBox" id="ctl00_Body_CategoriesTreeViewn3CheckBox" title="Volunteer SubCat 2" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s2\\7')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt3');" id="ctl00_Body_CategoriesTreeViewt3">Volunteer SubCat 2</a></td>
                  </tr>
            </table>
      </div><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn4CheckBox" id="ctl00_Body_CategoriesTreeViewn4CheckBox" title="Advocating" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s3')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt4');" id="ctl00_Body_CategoriesTreeViewt4">Advocating</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn5CheckBox" id="ctl00_Body_CategoriesTreeViewn5CheckBox" title="Giving" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s4')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt5');" id="ctl00_Body_CategoriesTreeViewt5">Giving</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX4iascjIf74mJB0-PvYVJWk1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn6CheckBox" id="ctl00_Body_CategoriesTreeViewn6CheckBox" title="Serving" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s5')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt6');" id="ctl00_Body_CategoriesTreeViewt6">Serving</a></td>
            </tr>
      </table>
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 17168645
Check this:



<script>
function toggleAll(theBox){
  var theForm = theBox.form;
  var elem = theForm.elements;
  var pref = theBox.name.split("_All")[0];
  for(var i=0;i<elem.length;i++){
    if(elem[i].name.indexOf(pref)==0){
      elem[i].checked = theBox.checked;
    }
  }
}
</script>
<form>
 <table width="350">
                        <tr>
                            <td valign="top">
                                Regions:<br><input type="checkbox" name="ctl00_Body_RegionsTreeview_All" onClick="toggleAll(this)" title="All Regions" /> All</td>
                            <td>Categories:<br><input type="checkbox" name="ctl00_Body_CategoriesTreeView_All" onClick="toggleAll(this)" title="All Categories" /> All</td>
                        </tr>




0
 

Author Comment

by:JeffDrummond
ID: 17178986
Thanks Zvonko!  Works perfectly!
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17179990
You are welcome.
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

Suggested Solutions

Title # Comments Views Activity
Close "X" button on window popup in Firefox 7 36
jquery wizard next doesn't go to top of tab 4 52
jQuery Parallax 1 38
Javascript and Jquery not firing 9 39
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 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

23 Experts available now in Live!

Get 1:1 Help Now