I have an existing RadioButtonList
on a page and need to set the second button to be checked as default instead of the first.
I probably need to do it with javascript
on the page as I cannot edit the original control.
<list:RadioButtonList runat="server" Class="class" Text="text"
AlternativeText="alternative text" />
Any idea how i can detect the control and set its default value?
I have an existing RadioButtonList
on a page and need to set the second button to be checked as default instead of the first.
I probably need to do it with javascript
on the page as I cannot edit the original control.
<list:RadioButtonList runat="server" Class="class" Text="text"
AlternativeText="alternative text" />
Any idea how i can detect the control and set its default value?
Share Improve this question asked Feb 1, 2013 at 11:56 dizzytri99erdizzytri99er 9309 silver badges25 bronze badges1 Answer
Reset to default 4If you use ASP.NET you can set the following:
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Selected="True" ></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:RadioButtonList>
I've added the attribute Selected="True", so you always have a default value selected.
You can also do this in code:
if (RadioButtonList1.SelectedIndex == -1) //-1 is the indication of none selected
{
RadioButtonList1.SelectedIndex = 2; //select index 2 (can also be value or text)
}