我已經找到了這段代碼,但我想知道是否有更簡化的方法來做到這一點。asp.net - 以單選按鈕組的形式獲取所選項目的文本
因此,例如,而不是所有的if語句,你可以有一行寫着Label1.text = 「您選擇了」 & 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" />