![]() |
| ||
| counting checkboxes 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. |
| ||
| Re: counting checkboxes Coudn't you just add a counter to your logic? int myCounter = 0; |
| ||
| Re: counting checkboxes yes i tried that...however when i return the count..for example if i check 3 checkboxes...it will return 123. so it is counting them right...but i only need the 3...hehe. thank you for your response....any other clues? |
| ||
| Re: counting checkboxes I'm sorry, I don't understand your reply. There is no way the code above would return the value "123" for the "myCounter" integer. If there are 3 checkboxes, the value would be "3" after the loop completes. |
| ||
| Re: counting checkboxes 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] |
| ||
| Re: counting checkboxes Hi, can u try this. Quote:
Thanks, Kedar |
| All times are GMT -4. The time now is 2:33 pm. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC