Datalists and Checkboxes

G

Guest

I have a Datalist that contains several fields, one of which is a checkbox.
When the user clicks a submit button, I need to be able to determine how many
of the checkboxes in the datalist were checked. I am doing the page in
ASP.NET using VB.

Thanks, in advance, for any assistance any of you could provide.
 
G

Guest

Sorry, I don't speak VB ;-) so I can't give you exact code.

But the easiest way to do this is to loop through the "Items" collection of
the datalist. Use the "FindControl" method on each DataListItem to find your
checkbox, then you should be able to work out if it's checked or not. In C#
it would look like this:

int checkCount = 0;
foreach (DataListItem item in myDataList) {
Checkbox cbx = (Checkbox) item.FindControl("checkboxID");
if (cbx.Checked) {
checkCount++;
}
}

Hope that helps -
/gerrod
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,052
Latest member
KetoBeez

Latest Threads

Top