473,750 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I traverse through all of the checkboxes in my datagrid using javascript?

I posted this question to comp.lang.javas cript but didn't get a
response, so I'll try here.

I am using ASP.NET and I have a datagrid. One of the columns in my
grid is all checkboxes. When the user clicks on a certain button on
the page, which is not in the grid, I want to be able to traverse
through all the checkboxes in that column and see how many are
checked. This is so that I can give them a confirmation dialog before
I do an action on the selected rows. How can I use javascript to
traverse through the checkboxes and count how many are checked?
Thanks in advance
Nov 18 '05 #1
2 3194
"john" <jo********@yah oo.com> wrote in message
news:29******** *************** ***@posting.goo gle.com...
I posted this question to comp.lang.javas cript but didn't get a
response, so I'll try here.

I am using ASP.NET and I have a datagrid. One of the columns in my
grid is all checkboxes. When the user clicks on a certain button on
the page, which is not in the grid, I want to be able to traverse
through all the checkboxes in that column and see how many are
checked. This is so that I can give them a confirmation dialog before
I do an action on the selected rows. How can I use javascript to
traverse through the checkboxes and count how many are checked?
Thanks in advance


Hi John,
<asp:CheckBoxLi st id=CheckBoxList 1 runat="server">
<asp:ListItem Value="1">Item1 </asp:ListItem>
<asp:ListItem Value="2">Item2 </asp:ListItem>
<asp:ListItem Value="3">Item3 </asp:ListItem>
<asp:ListItem Value="4">Item4 </asp:ListItem>
</asp:CheckBoxLis t>

<script language=javasc ript>
// Go through all items of a check list control
var table = document.getEle mentById ('CheckBoxList1 ');
var cells = table.getElemen tsByTagName("td ");
var ctlr;

for (var i = 0; i < cells.length; i++)
{
ctrl = cells[i].firstChild;

if (ctrl.type == 'checkbox')
alert ('Name:' + ctrl.name + '; selected: ' + ctrl.checked);
}
</script>

Note that this is just a CheckBoxList. I have an <asp:Panel> control which
rendered as a table which is why I did traversal through <td>s. A datagrid
is a table as well. I don't know how many columns your datagrid has and
which column contains checkboxes, but the idea should be the same---through
DOM calls you can navigate controls in your datagrid and find checkboxes
this way.

If you want to traverse checkboxes in your datagrid server-side it's
somewhat different.
--
Milan Negovan
www.AspNetResources.com
Essential recources for ASP.NET developers
Nov 18 '05 #2
Thanks, this worked for me.
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2254
by: john | last post by:
I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the user clicks on a certain button on the page, which is not in the grid, I want to be able to traverse through all the checkboxes in that column and see how many are checked. This is so that I can give them a confirmation dialog before I do an action on the selected rows. How can I use javascript to traverse through the checkboxes and count...
1
2050
by: kannadasan | last post by:
Hi all I am using Datagrid where i place checkboxes in one column with some other columns.The purpose is, if i select the checkboxes and clicks the submit buton Email has to go to the selected Categories. The problem here is after clicking submit button i found the checkboxes are not unchecked (cleared) even though i put EnableViewState="False".
7
2421
by: DJ Dev | last post by:
Hi All, I have a complex problem. I have dropdownlists (usually 3-5) and the user selects some value from these and for each value selected, datagrids are shown to the user. I am creating the Datagrids dynamically using a loop depending on the number of Dropdownlists. The datagrids also have a checkbox template column. Now my problem is that how can I access the values selected by the user from these checkboxes. He checks one or more...
0
1116
by: Angela | last post by:
Hi I have a datagrid with checkboxes besides a list of names. What I want is for the user to select the checkboxes and press 'Preview' and a new window opens with a print friendly list of the selected contact details. I can get the selected IDs via my server side code but can't target a new window to open.
2
2463
by: Mortar | last post by:
i have a datagrid with 2 columns. the 1st column contains an id which will be used by the database for the selected checkbox records. the 2nd column is a template column containing a server checkbox control. where i'm at: i can retrieve a count of the selected checkboxes, but don't know how to get the related id's (in the 1st column).
5
7319
by: sianan | last post by:
I have an ASP.NET custom control, which contains a DataGrid with checkboxes. I am trying to figure out how to retrieve the selected records, based on the checkbox's checked state. I want to send the results to a list control on the containing .ASPX page. Here is what I have in my code behind (C#): <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication5.WebForm1" %> <!DOCTYPE HTML PUBLIC...
3
1809
by: GatorBait | last post by:
Hi all, I'm using a datagrid for the first time and I am running into some problems that I hope someone can help me with. I have a datagrid with 18 rows and 5 columns....column 1 is just text and columns 2-5 are checkboxes. Some of the checkboxes have to be invisible, and in some cases some of the checkboxes have be be enabled=false. I have it now so that the entire grid is populated correctly, but I am having an extremely difficult...
7
2516
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To implement this, if I am not mistaken, I HAVE TO post the Form first i.e. set the AutoPostBack property of the CheckBox to True. Without posting the Form, I don't think the BackColor of the checked row can be changed using ASP.NET, isn't it? Of...
10
5207
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named 'CheckAllRows' on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the...
0
9000
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9577
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9396
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9339
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6804
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4713
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2804
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.