Solved

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

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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