Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-07-01
3
Medium Priority
?
869 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 1000 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 1000 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

Independent Software Vendors: 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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

636 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