我找到了这段代码,但我想知道是否有更简化的方法来做到这一点。
因此,例如,除了拥有所有 if 语句之外,您还可以在一行中显示 Label1.text = "You selected " & RadioGroup1.Text
Sub SubmitBtn_Click(Sender As Object, e As EventArgs)
If Radio1.Checked Then
Label1.Text = "You selected " & Radio1.Text
ElseIf Radio2.Checked Then
Label1.Text = "You selected " & Radio2.Text
ElseIf Radio3.Checked Then
Label1.Text = "You selected " & Radio3.Text
End If
End Sub
和
<asp:RadioButton id=Radio1 Text="Typical" Checked="True" GroupName="RadioGroup1" runat="server" />
<asp:RadioButton id=Radio2 Text="Compact" GroupName="RadioGroup1" runat="server"/>
<asp:RadioButton id=Radio3 Text="Full" GroupName="RadioGroup1" runat="server" />
<asp:Button text="Submit" OnClick="SubmitBtn_Click" runat=server/>
<asp:Label id=Label1 Font-Bold="true" runat="server" />