简体   繁体   English

vb.net单选按钮列表检查是否已选中

[英]vb.net radio button list check if selected

I have the following: 我有以下内容:

    <asp:RadioButtonList ID="rbIsRep" runat="server"  RepeatDirection="horizontal" >
        <asp:ListItem Value="1" >Yes</asp:ListItem>
        <asp:ListItem Value="0" >No</asp:ListItem>
    </asp:RadioButtonList>

how do I check if the radiobuttonlist has any selected items? 如何检查radiobuttonlist是否有任何选定的项目?

Use the SelectedIndex proprty to check if anything is selected and the SelectedItem property to get the selected item's text: 使用SelectedIndex proprty如果选择任何和检查SelectedItem属性获取所选项目的文本:

If rbIsRep.SelectedIndex > - 1 Then
    Dim selectedItemsText = "You selected: " & rbIsRep.SelectedItem.Text
End If

You can change the selection programmatically for example with the SelectedValue property. 您可以通过编程方式更改选择,例如使用SelectedValue属性。

rbIsRep.SelectedValue = "0"

or declaratively from aspx 或者从aspx声明

<asp:RadioButtonList ID="rbIsRep" runat="server"  RepeatDirection="horizontal" >
    <asp:ListItem Value="1" >Yes</asp:ListItem>
    <asp:ListItem Selected="True" Value="0" >No</asp:ListItem>
</asp:RadioButtonList>

One way to do it: 一种方法:

var hasSelection = yourRadioButtonList.SelectedIndex != -1;

And for VB.NET: 而对于VB.NET:

Dim hasSelection = yourRadioButtonList.SelectedIndex <> -1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM