can you describe your requirement as if you want to create a list of RadioButton you can use RadioButtonList and if you want to create a RadioButton through code you can create the object of the radio button. Then use the Form.Controls.Add method and pass
the radio buttons's object name as a parameter.
Thanks and best regards,
Faraz Shah Khan
SFDC Certified Developer, MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
Thanks for your fastest response you did answer my question. Assuming that i generate the radio buttons and clicked radio button1. How can i show a message that specificly tells radio button is selected like "Radio button 1 Selected"?
I have a list of questions and want the radio buttons (Answers) to be inserted under each question. When I add the radio buttons, form1.Controls.Add(button);
form1.Controls.Add(button2); adding like this they are all grouped together at the bottom of the page. How would you add the radiobuttons in the item_created event of a repeater or datalist to the datalist collection? Do you know how to do this.
danab
Member
4 Points
18 Posts
creating dynamic radio buttons
May 14, 2007 09:40 AM|LINK
Hello,
Could you guys please help me creating radio buttons dynamically using asp.net.
Regards
farazsk11
Star
8347 Points
1384 Posts
Re: creating dynamic radio buttons
May 14, 2007 09:53 AM|LINK
Hi,
can you describe your requirement as if you want to create a list of RadioButton you can use RadioButtonList and if you want to create a RadioButton through code you can create the object of the radio button. Then use the Form.Controls.Add method and pass the radio buttons's object name as a parameter.
Thanks and best regards,
SFDC Certified Developer, MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
kipo
All-Star
16475 Points
2811 Posts
Re: creating dynamic radio buttons
May 14, 2007 09:54 AM|LINK
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);
danab
Member
4 Points
18 Posts
Re: creating dynamic radio buttons
May 14, 2007 10:22 AM|LINK
Thanks for your fastest response you did answer my question. Assuming that i generate the radio buttons and clicked radio button1. How can i show a message that specificly tells radio button is selected like "Radio button 1 Selected"?
Thanks in advance.
Regards
kipo
All-Star
16475 Points
2811 Posts
Re: creating dynamic radio buttons
May 14, 2007 02:05 PM|LINK
Here is the full code:
protected void Page_Load(object sender, EventArgs e)
{
CreateCheckBoxes();
}
private void CreateCheckBoxes()
{
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);
button.EnableViewState = true;
button2.EnableViewState = true;
button.AutoPostBack = true;
button2.AutoPostBack = true;
button.CheckedChanged += new EventHandler(button_CheckedChanged);
button2.CheckedChanged += new EventHandler(button2_CheckedChanged);
}
void button2_CheckedChanged(object sender, EventArgs e)
{
CheckBox check = (CheckBox)sender;
if (check.Checked)
{
Response.Write("Button2 is Checked");
}
}
void button_CheckedChanged(object sender, EventArgs e)
{
CheckBox check = (CheckBox)sender;
if (check.Checked)
{
Response.Write("Button1 is Checked");
}
}
GregT
Member
4 Points
4 Posts
Re: creating dynamic radio buttons
May 25, 2007 07:37 PM|LINK
I have a list of questions and want the radio buttons (Answers) to be inserted under each question. When I add the radio buttons, form1.Controls.Add(button);
form1.Controls.Add(button2); adding like this they are all grouped together at the bottom of the page. How would you add the radiobuttons in the item_created event of a repeater or datalist to the datalist collection? Do you know how to do this.
Thank you.
GT
kipo
All-Star
16475 Points
2811 Posts
Re: creating dynamic radio buttons
May 27, 2007 09:06 PM|LINK
Try with this: