要關(guān)閉 RadioButtonList 的多選功能,您需要確保每個單選按鈕(RadioButton)在同一組中互斥。這可以通過設(shè)置 RadioButtonList 的 RepeatColumns
屬性來實現(xiàn)。
以下是一個簡單的示例:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatColumns="1">
<asp:ListItem Text="Option 1" Value="1"></asp:ListItem>
<asp:ListItem Text="Option 2" Value="2"></asp:ListItem>
<asp:ListItem Text="Option 3" Value="3"></asp:ListItem>
</asp:RadioButtonList>
在這個示例中,我們將 RepeatColumns
屬性設(shè)置為 “1”,這意味著所有單選按鈕都將顯示在同一列中,并且用戶只能選擇一個選項。
注意:如果您需要讓用戶能夠取消選擇,請?zhí)砑右粋€沒有值和文本的 ListItem,如下所示:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatColumns="1">
<asp:ListItem Text="" Value=""></asp:ListItem>
<asp:ListItem Text="Option 1" Value="1"></asp:ListItem>
<asp:ListItem Text="Option 2" Value="2"></asp:ListItem>
<asp:ListItem Text="Option 3" Value="3"></asp:ListItem>
</asp:RadioButtonList>
這樣,用戶可以點擊第一個空白選項來取消選擇。