Solved

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

Posted on 2009-07-01
3
853 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

777 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