?
Solved

Retriveing checkbox value in ASP.NET

Posted on 2007-10-15
4
Medium Priority
?
904 Views
Last Modified: 2013-11-07
I have list of dynamic html checkboxes  like below in ASP.NET page

<input name="SecuritySuite1" type="checkbox" value="" />
<input name="SecuritySuite2" type="checkbox" value="" />
<input name="SecuritySuite3" type="checkbox" value="" />
.
.
.
<input name="SecuritySuite  n" type="checkbox" value="" />

How do I access the values in the codebehind dynamically since I dont know the name of SecuritySuite ...n.
How do I loop to the Request.Params collection for these checkboxes?


0
Comment
Question by:AdibRahman77
  • 3
4 Comments
 
LVL 16

Expert Comment

by:McExp
ID: 20081561
Are the checkboxes created from aspx code?

If so you could use a CheckBoxList Control and then dynamically add the items and then subsequently itterate thorugh the items collection of the CheckBoxList?
0
 

Author Comment

by:AdibRahman77
ID: 20081925
Can you show me an example of dynamically creating checkboxlist  in the codebehind?
0
 
LVL 16

Accepted Solution

by:
McExp earned 1500 total points
ID: 20081981
You should find in the following example a demo of how to dynamically create a list of items and then process the list on form postback.

--- In your aspx ---
    <form id="form1" runat="server">
        <asp:CheckBoxList ID="CheckBoxList1" runat="server"/>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        Selected Values:<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </form>
--- In your Codebehind ---
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            for (int i = 0; i < 3; i++)
            {
                CheckBoxList1.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string selected = "";
        foreach (ListItem checkbox in CheckBoxList1.Items)
        {
            if (checkbox.Selected)
            {
                selected += checkbox.Value;
            }
        }
        Label1.Text = selected;
    }

Enjoy!
0
 
LVL 16

Expert Comment

by:McExp
ID: 20282842
Have you resolved your problems?

If so shall we close this off?

We might even win the laptops!!!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses

850 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