C# radiobutton 在Web應(yīng)用中的實(shí)現(xiàn)

c#
小樊
83
2024-07-13 22:37:24

在ASP.NET Web應(yīng)用中,可以使用ASP.NET的RadioButton控件來(lái)實(shí)現(xiàn)單選按鈕(RadioButton)。以下是一個(gè)簡(jiǎn)單的示例:

<asp:RadioButtonList ID="RadioButtonList1" runat="server">
    <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>

在代碼后端中,可以通過(guò)以下方式來(lái)獲取選中的單選按鈕的值:

string selectedValue = RadioButtonList1.SelectedValue;

也可以通過(guò)以下方式來(lái)檢查哪個(gè)單選按鈕被選中:

if (RadioButtonList1.SelectedItem != null)
{
    string selectedText = RadioButtonList1.SelectedItem.Text;
    string selectedValue = RadioButtonList1.SelectedItem.Value;
}

這樣就可以在ASP.NET Web應(yīng)用中實(shí)現(xiàn)單選按鈕(RadioButton)的功能。

0