早上好堆栈溢出!
我有一个小问题,我正在努力解决这件事,这让我的生活变得糟透了!
在我的 .aspx 页面上,我希望能够根据用户选择(单选按钮列表)显示和隐藏某些面板。
例如,在我的 aspx 页面中,我有;
<form id="form1" runat="server">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:RadioButtonList>
<asp:Panel ID="Panel1" runat="server" Width="50%">
Visible or not visible depending on radio choice<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Panel>
</form>
然后在我的 aspx.vb 中有;
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If RadioButtonList1.SelectedItem.Equals(Nothing) Then
Panel1.Visible = False
Else
RadioButtonList1.SelectedItem.Equals(3)
Panel1.Visible = True
End If
End Sub
我还尝试了此代码的一些不同变体,以及选择语句。如果有人可以就如何解决这个问题提供任何建议,将不胜感激
非常感谢,菲尔
编辑:
经过进一步的尝试和对 msdn 的一些阅读,我现在有了;
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Show or Hide the Panel contents.
If RadioButtonList1.SelectedItem.Equals(3) Then
Panel1.Visible = True
Else
Panel1.Visible = False
End If
End Sub
但是当我尝试运行我得到的代码时;
此行上的“对象引用未设置为对象的实例” If RadioButtonList1.SelectedItem.Equals(3) Then