要設(shè)置RadioButtonList的默認(rèn)選項(xiàng),您可以使用SelectedIndex
屬性。首先,確保您已經(jīng)為RadioButtonList中的每個(gè)RadioButton設(shè)置了Value
屬性,然后通過將SelectedIndex
屬性設(shè)置為對應(yīng)RadioButton的索引來選擇默認(rèn)選項(xiàng)。
以下是一個(gè)簡單的示例:
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="Option 1" Value="1" />
<asp:ListItem Text="Option 2" Value="2" />
<asp:ListItem Text="Option 3" Value="3" />
</asp:RadioButtonList>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" />
Page_Load
事件處理程序中)設(shè)置默認(rèn)選項(xiàng):protected void Page_Load(object sender, EventArgs e)
{
// 設(shè)置默認(rèn)選項(xiàng),例如,選擇"Option 2"
RadioButtonList1.SelectedIndex = 1;
}
在這個(gè)例子中,當(dāng)頁面加載時(shí),"Option 2"將被設(shè)置為默認(rèn)選項(xiàng)。當(dāng)用戶點(diǎn)擊"Submit"按鈕時(shí),服務(wù)器端代碼將處理所選選項(xiàng)。