gpt4 book ai didi

c# - 影响现有RadioButtonList设置默认值

转载 作者:行者123 更新时间:2023-11-28 16:06:40 25 4
gpt4 key购买 nike

我在页面上已有一个 RadioButtonList,需要将第二个按钮设置为默认检查,而不是第一个。

我可能需要在页面上使用 javascript 来完成此操作,因为我无法编辑原始控件。

<list:RadioButtonList runat="server" Class="class" Text="text"
AlternativeText="alternative text" />

知道如何检测控件并设置其默认值吗?

最佳答案

如果您使用 ASP.NET,您可以设置以下内容:

<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>

我添加了属性 Selected="True",因此您始终会选择默认值。

您也可以在代码中执行此操作:

if (RadioButtonList1.SelectedIndex == -1) //-1 is the indication of none selected
{
RadioButtonList1.SelectedIndex = 2; //select index 2 (can also be value or text)
}

关于c# - 影响现有RadioButtonList设置默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14645783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com