Solved

how to make a dymanic checkboxes in c# asp.net

Posted on 2011-03-20
4
263 Views
Last Modified: 2012-06-22
how to make a dymanic checkboxes in c# asp.net such as if i want a for loop of 10 checkboxes on the page.
0
Comment
Question by:cbrune
[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
  • 3
4 Comments
 
LVL 2

Expert Comment

by:ramkihardy
ID: 35178219
use check box list to add 10 checkboxes dynamically,
then use this code to find the checkbox which is selected..
foreach(ListItem item in CheckBoxList1.Items)
            if (item.Selected)
            {
                //Do any action
            }
if you create checkboxes it is hard to find which is selected instead of checkboxlist....
0
 

Author Comment

by:cbrune
ID: 35178227
can you give me more code then this? sorry im a beginner at asp.net
0
 
LVL 2

Expert Comment

by:ramkihardy
ID: 35178239
could you please tell me from where you want to load the values for those checkboxes
0
 
LVL 2

Accepted Solution

by:
ramkihardy earned 500 total points
ID: 35178262
This is how i am populating a checkboxlist from a table
i ll first establish a connection and get the values from the tables form the database..and populate the checkboxlist..
CheckBoxList CHK = new CheckBoxList();
                CHK.ID = "CHK" + currentQuestion.SurveyQuestionId;
                CHK.DataSource = currentQuestion.LookupValues;
                CHK.DataTextField = "LookUpValue";
                CHK.DataValueField = "SurveyLookUpId";
                CHK.RepeatDirection = RepeatDirection.Horizontal;                
                CHK.BorderWidth = 0;
                //CHK.RepeatColumns = currentQuestion.LookupValues.Count;
                //CHK.RepeatLayout = RepeatLayout.Flow;
                CHK.RepeatColumns = 1;
                CHK.CssClass = "dCheckBox";
                CHK.DataBind();
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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