Solved

checkbox c# ASP.NET

Posted on 2009-05-19
2
908 Views
Last Modified: 2013-12-17
I have several dynamic checkbox (i use html checkbox, but if necessary i use asp.net checkbox) with same name and same ID, how do I retrieve the values checked when an asp: button is clicked?

I use C# on ASP.NET page.

thanks for help.
0
Comment
Question by:fsouzabrasil
2 Comments
 
LVL 2

Accepted Solution

by:
clinton_cunningham earned 500 total points
ID: 24427726
You cant have a page with multiple controls with the same ID. It should not compile and if it did it would be a really bad practice (same name also bad practice). These best thing you could do is to create a dynamic ID as you populate the page with controls. i.e. have a integer counter, i, and then increment it by 1 every-time you add a control.
so eventually you page will have a list of controls on the page like this:
<asp:checkboxlist id="CheckBoxList1" runat="server">
 <asp:Checkbox id="checkbox1" name="checkbox" runat="server">
 <asp:Checkbox id="checkbox2" name="checkbox" runat="server">
 <asp:Checkbox id="checkbox3" name="checkbox" runat="server">
<asp:checkbox/>

when your asp.net button is pressed you can cycle through all your controls like this:

string values;

foreach ( CheckBox box in CheckBoxList1)
 if if (box.Checked)
 {
   values = values + box.Value;    
}

0
 
LVL 4

Author Comment

by:fsouzabrasil
ID: 24431069
this checkboxes is grouped by category and i have one or more category, can i have dynamic CheckBoxList? how can I learn how to complete the loop? There is an equivalent function to the eval javascript, but to page compiled?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question