473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to check multiple checkboxes in a asp:DataList without refreshing screen

17
I have a page that has a datalist that has an item template that has a checkbox. I have a select all and unselect all button that when clicked refreshes the screen and either checks or unchecks all the checkboxes. How can I just update the checkboxes without refreshing the entire page?

Thank you
Apr 2 '12 #1
5 3969
Frinavale
9,735 Expert Mod 8TB
In JavaScript, call the getElementsByTagName to retrieve all of the inputs in the element that contains the check boxes.

Loop through the elements retrieved and check/uncheck any "checkbox" type of elements.

I don't remember if a DataList has a containing element...so I'll say, if you put the DataList within a Panel you can call the getElementsByTagName on the panel-div.

For example (the following is not tested):

Expand|Select|Wrap|Line Numbers
  1. function checkAllCheckBoxes(){
  2.   var checkAllCheckbox = document.getElementById('<%=checkAllCheckbox.ClientID%>');
  3.   var container = document.getElmentById('<%=containerPanel.ClientID%>');
  4.   var inputsInContainer = container.getElementsByTagName('input');
  5.  
  6.   for (i = 0; i < inputsInContainer .length; i++) {
  7.     if (inputsInContainer[i].type == "checkbox") {
  8.       inputsInContainer[i].checked = checkAllCheckbox.checked;
  9.     }
  10.   }
  11. }
Apr 2 '12 #2
Jerry W
17
Frinavale,

Thank you for your reply. Here is what I have working
Expand|Select|Wrap|Line Numbers
  1.  <script type="text/javascript">
  2.       function checkAllCheckBoxes() {
  3.         var container = document.getElementById('<%=pnlCheck.ClientID%>');
  4.         var inputsInContainer = container.getElementsByTagName('input');
  5.  
  6.         for (i = 0; i < inputsInContainer.length; i++) {
  7.           if (inputsInContainer[i].type == "checkbox") {
  8.             inputsInContainer[i].checked = false;
  9.           }
  10.         }
  11.       }
  12.     </script>
  13.  
My issue is that I want to check and uncheck these checkboxes without the entire page refreshing. Should I be using a script manager and an ajax update panel to make that happen? Right now I just have a asp:panel and a asp:datalist both runat="server".

Thank you again for your help.
Apr 3 '12 #3
Frinavale
9,735 Expert Mod 8TB
JavaScript is executed within the browser...it runs "client-side".
There are no server requests made.

If you are experiencing full page refreshes using the code you posted, then you have something set to autopostback that shouldn't be set.

If you want to do the selecting/unselecting in server code, then place the DataList within an UpdatePanel. Anything in the UpdatePanel will cause asynchronous post-backs to occur. When the request comes back from the server, only the elements within the UpdatePanel will be updated.



-Frinny
Apr 3 '12 #4
Jerry W
17
Frinavale,

I want to do the checking and unchecking on the client's browser.
There are other controls within my page that have autopostback set to true but not the control with the checkboxes. I have a datalist and two image buttons that all have runat="server". I have since created two input buttons so they are local. If i'm doing this on the client do I need to do any ajax or should my javascript just change the checkboxes? If I wrap my datalist in an update panel everything works fine but when I remove the updatepanel I see it reloading the page.

Thanks agian for your help.
Apr 3 '12 #5
Frinavale
9,735 Expert Mod 8TB
So you need to generate the JavaScript in your server side code and then register it with your ScriptManager.

-Frinny
Apr 3 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: GraVity via DotNetMonster.com | last post by:
Hello all I am new to asp.net or web programming I have a requirement, I have to submit a document to another server using my webpage, there is a perticular protocol for doing that. This protocol...
1
by: Chris Fink | last post by:
Hello, Does anyone know of a way to prevent the asp:datalist control from creating html code table and table row tags when it is rendered. I have normally just incorporated this into the layout...
2
by: jdi | last post by:
Hello, I have a seemingly basic question about ASP.NET. I would like to create a page containing an image, which keeps swapping the url of the image source, without refreshing the entire page. ...
3
by: Harry | last post by:
Hi, Can anyone tell me why the below code does not work. I dont get any errors, but nor does the Text for the asp:label get set. Thanks in advance as always H
3
by: Aitham alama | last post by:
Hi There, My question is as following, I have a webform (Webform1) which contains one label control and command button, when the user clicks the button another webform (Webform2) appears,...
3
by: Wei | last post by:
Hi, I have a page written in ASP.net c# witch has a datalist with 200 records (in Itemtemplate). Each record includes nine webcontrol radio buttons as a group. The user will need to check...
0
by: bryanp10 | last post by:
I have a DataList on my page which contains multiple DropDownLists. My page defaults to showing six rows in the DataList. I want the ability to dynamically add rows if needed. Right now I'm just...
2
by: Ben | last post by:
Hi, One ASP.NET transactional page conducts a long transaction in a button click function. I want to display the transaction progress info in label control without refreshing page. It is...
2
by: BengtPelle | last post by:
I have a page with two Datalists containing X number of ImageButtons. When the user clicks on an image in Datalist1 I need to copy the image to "Obverseimg" when the user clicks an image in...
3
by: user | last post by:
Hi, let's say a page loads on a browser. Without refreshing the page, multiple textboxes within the page gets real time data @ a few seconds interval. what is the logic behind to achieve...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.