Reputation: 5343
I am creating radio button dynamically inside asp:table. iI want to get the id of the selected radio button.
How to get its ID.
RadioButton radioButton = new RadioButton();
radioButton.ID = id + "RadioButton";
radioButton.ToolTip = text;
radioButton.Attributes.Add("id", id);
radioButton.GroupName = categoryID + "Questions";
radioButton.EnableViewState = true;
radioButton.AutoPostBack = true;
radioButton.Checked = isSelected;
radioButton.CssClass = style;
TableCell cell = new TableCell();
cell.HorizontalAlign = HorizontalAlign.Left;
cell.Controls.Add(radioButton);
TableRow row = new TableRow();
row.Cells.Add(cell);
table.Rows.Add(row);
Upvotes: 0
Views: 2763
Reputation: 5343
Solution. i am posting this solution to help others.
RadioButton rb = new RadioButton();
foreach (TableRow tr in QuestionTable.Controls)
{
foreach (TableCell tc in tr.Controls)
{
if (tc.Controls[0] is RadioButton)
{
rb = (RadioButton)tc.Controls[0];
if (rb.Checked)
{
string aa = rb.ID;
}
break;
}
}
}
Upvotes: 1
Reputation: 12842
Why dont you use jQuery.
Specify a class for thr radio button
Loop through the class using 'each' function
Then in 'each' function, check whether (this) object is decorated with 'selected' or 'checked' property.
Upvotes: 0