Solved

how to dynamically create radio buttons and retrieve the selected radiobutton info in C#

Posted on 2009-07-01
3
847 Views
Last Modified: 2012-05-07
I need to create Dynamic radiobuttons and retrieve the selected radio button's text.
0
Comment
Question by:Akhil06
3 Comments
 
LVL 9

Accepted Solution

by:
AsishRaj earned 250 total points
ID: 24758421
to create dynamic radio buttons



RadioButton button = new RadioButton();

  RadioButton button2 = new RadioButton();

  button.Text = "Button1";

  button.Checked = false;

  button.GroupName = "myButtons";

  button2.Text = "Button2";

  button2.Checked = false;

  button2.GroupName = "myButtons";

  form1.Controls.Add(button);

  form1.Controls.Add(button2); 

Open in new window

0
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 250 total points
ID: 24758423
You should add a Panel Control  to your .aspx page:
 <asp:Panel ID="Panel1" runat="server">
    </asp:Panel>

Then add your RadioButtons to it like below in code behind:

 RadioButton radio1 = new RadioButton();
        radio1.Text = "Yes";
        Panel1.Controls.Add(radio1);
RadioButton radio2 = new RadioButton();
        radio2.Text = "No";
        Panel1.Controls.Add(radio2);


You can also use RadioButtonList and then add RadioButtons to it like below:

 <asp:RadioButtonList ID="RadioButtonList1" runat="server">
    </asp:RadioButtonList>

 RadioButtonList1.Items.Add(new ListItem("One"));
 RadioButtonList1.Items.Add(new ListItem("Two"));
 RadioButtonList1.Items.Add(new ListItem("Three"));

To Retrieve selected RadioButton when using RadioButtonList:
 string selectedValue = RadioButtonList1.SelectedValue;

It all depends on how your radio buttons are grouped.




0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

16 Experts available now in Live!

Get 1:1 Help Now