Hi,
I've got a page where a list of radiobuttons are added during run time, I need to take some action on a button click(also added on runtime) depending upon the selection made...
How do I achieve this???
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Lalit MPosted Jan 18, 2010, 7:10 AM
paul danielPosted Jan 18, 2010, 8:13 AM
Try this code
if (TextBox2.Text != string.Empty)
{
int rbCount = Convert.ToInt32(TextBox2.Text);
RadioButton[] radioButtons = new RadioButton[rbCount];
for (int i = 0; i < rbCount; ++i)
{
radioButtons[i] = new RadioButton();
radioButtons[i].GroupName = "rb";
radioButtons[i].Text = Convert.ToString(i);
PlaceHolder1.Controls.Add(radioButtons[i]);
}
}
Radio Button List:
if (TextBox2.Text != string.Empty)
{
int rbCount = Convert.ToInt32(TextBox2.Text);
RadioButtonList rbList = new RadioButtonList();
for (int i = 1; i <= rbCount; ++i)
{
rbList.Items.Add(new ListItem(Convert.ToString(i), Convert.ToString(i)));
}
PlaceHolder1.Controls.Add(rbList);
}