469,579 Members | 1,281 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

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

I posted this question to comp.lang.javascript 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 2997
"john" <jo********@yahoo.com> wrote in message
news:29**************************@posting.google.c om...
I posted this question to comp.lang.javascript 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:CheckBoxList id=CheckBoxList1 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:CheckBoxList>

<script language=javascript>
// Go through all items of a check list control
var table = document.getElementById ('CheckBoxList1');
var cells = table.getElementsByTagName("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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by kannadasan | last post: by
7 posts views Thread by DJ Dev | last post: by
2 posts views Thread by Mortar | last post: by
3 posts views Thread by GatorBait | last post: by
7 posts views Thread by rn5a | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.