•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 392,318 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,837 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2212 | Replies: 5
![]() |
•
•
Join Date: Sep 2005
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
All,
i have a bunch of dynamic checkboxes created in a datagrid, and i have the results going to a database when they are checked. question is how do i count the total # of checkboxes checked. here is the code i have that loops through the checkboxes to submit to the db.
foreach (DataGridItem spriden_ID in dgEmployees.Items)
{
CheckBox cbSpriden = (CheckBox) spriden_ID.FindControl("cbSpriden");
if (cbSpriden.Checked)
{
//Stuff to add to db here
}
else
{
lblStatus.Text ="Scheduling failed: " + addCourses.ErrorMessage;
}
}
Once the update to the DB succeeds i want to display the count of all the checkboxes submitted..how would i do this?? thanks in advance for any help.
i have a bunch of dynamic checkboxes created in a datagrid, and i have the results going to a database when they are checked. question is how do i count the total # of checkboxes checked. here is the code i have that loops through the checkboxes to submit to the db.
foreach (DataGridItem spriden_ID in dgEmployees.Items)
{
CheckBox cbSpriden = (CheckBox) spriden_ID.FindControl("cbSpriden");
if (cbSpriden.Checked)
{
//Stuff to add to db here
}
else
{
lblStatus.Text ="Scheduling failed: " + addCourses.ErrorMessage;
}
}
Once the update to the DB succeeds i want to display the count of all the checkboxes submitted..how would i do this?? thanks in advance for any help.
Coudn't you just add a counter to your logic?
int myCounter = 0;
foreach (DataGridItem spriden_ID in dgEmployees.Items)
{
CheckBox cbSpriden = (CheckBox) spriden_ID.FindControl("cbSpriden");
if (cbSpriden.Checked)
{
//Stuff to add to db here
myCounter++;
}
else
{
lblStatus.Text ="Scheduling failed: " + addCourses.ErrorMessage;
}
}•
•
Join Date: Sep 2005
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
I agree with tgreer, his example would never return "123". The only thing I can think is that you are using a string as your counter variable and concatenating it rather than using an integer and incrementing it. Below is the only feasible code I can think of to duplicate your resuls (example is generic).
[HTML]string[] arr = new string[]{"a", "b", "c"};
string count = string.Empty;
for (int i = 0;i < arr.length; i++)
{
//do something with the string
//update counter
count += (i + 1);
}[/HTML]
[HTML]string[] arr = new string[]{"a", "b", "c"};
string count = string.Empty;
for (int i = 0;i < arr.length; i++)
{
//do something with the string
//update counter
count += (i + 1);
}[/HTML]
•
•
Join Date: Nov 2005
Location: Mountain View, CA
Posts: 47
Reputation:
Rep Power: 3
Solved Threads: 1
Hi,
can u try this.
Thanks,
Kedar
can u try this.
•
•
•
•
int myCounter = 0;
foreach (DataGridItem spriden_ID in dgEmployees.Items)
{
CheckBox cbSpriden = (CheckBox) spriden_ID.cells[index];
if (cbSpriden.Checked)
{
//Stuff to add to db here
myCounter++;
}
else
{
lblStatus.Text ="Scheduling failed: " + addCourses.ErrorMessage;
}
}
Thanks,
Kedar
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
- Count number of checkboxes being checked in asp.net (ASP)
- Counting post count (Growing an Online Community)
- Loop counting odd and even numbers (C++)
Other Threads in the ASP.NET Forum
- Previous Thread: Online Dating
- Next Thread: hide checkbox when field value is null



Linear Mode