Dim rl1 As RadioButtonList = New RadioButtonList()
所以您创建了上述内容?以上内容如何知道或与网页有什么关系?您在代码中创建的某些变量与您在网页上拥有的控件之间存在零关系?
你想要
MyRadioButtonOnTheWebPage.Selectedindex
大概是这样的:
RadioButtonList1.Selected 索引。
因此,您不会突然创建 + 暗淡一些与实际网页上的实际单选按钮列表无关的变量。我的意思是,如果您的网页上有 3 个 RadioButton 列表,那么上面指的是哪一个?
所以,如果你有一个像这样的 Radiobuttion 列表“1”:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
RepeatDirection="Horizontal">
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Tow</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
</asp:RadioButtonList>
然后是按钮回发,或者甚至说为单选按钮列表设置 autopostback = true。
然后在代码中你可以使用:
Debug.Print(RadioButtonList1.SelectedIndex)
Debug.Print(RadioButtonList1.SelectedValue)
所以上面会得到索引值,或者单选按钮的实际值。
如果您有 auto postback = true,那么您可以/将使用这样的事件(已更改),当您选择/更改单选按钮中的选择时将触发该事件
Protected Sub RadioButtonList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RadioButtonList1.SelectedIndexChanged
Debug.Print(RadioButtonList1.SelectedIndex)
Debug.Print(RadioButtonList1.SelectedValue)
End Sub