Solved

checkbox c# ASP.NET

Posted on 2009-05-19
2
884 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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now