是的,ASP.NET RadioButtonList 可以實現單選功能。RadioButtonList 是一個組合控件,它允許你在一組選項中選擇一個選項。默認情況下,RadioButtonList 控件中的所有 RadioButton 都是互斥的,這意味著在同一組中只能選擇一個 RadioButton。
要使用 RadioButtonList 實現單選功能,你需要執行以下步驟:
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="選項1" Value="Option1" />
<asp:ListItem Text="選項2" Value="Option2" />
<asp:ListItem Text="選項3" Value="Option3" />
</asp:RadioButtonList>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal;
RadioButtonList1.AutoPostBack = false;
}
}
這樣,當用戶在這組 RadioButton 中選擇一個選項時,其他選項將自動取消選中,從而實現單選功能。如果你需要在選擇一個選項時觸發某個事件(例如,調用服務器端方法),可以設置 RadioButtonList 的 AutoPostBack 屬性為 true,并為其指定一個 OnSelectedIndexChanged 事件處理程序。