By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a
Thanks, this worked for me.
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.