Solved

checkbox c# ASP.NET

Posted on 2009-05-19
2
927 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
[X]
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
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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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