Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

checkbox c# ASP.NET

Posted on 2009-05-19
2
917 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

829 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