"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