最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - affecting existing RadioButtonList to set a default value - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 4

If 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)
}
发布评论

评论列表(0)

  1. 暂无评论