Solved

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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