到目前为止,这是我尝试过的,无法让它发挥作用。我之前的格式略有不同,代码工作但只会隐藏/显示我在表单上做出另一个选择时想要的下拉列表。我正在寻找一种编写此代码的方法,以便只要复选框从false变为true,就会使dropdownlist可见或不可见,反之亦然
<asp:DropDownList ID="ddlcars" runat="server" AutoPostBack="True" Visible="False">
<asp:ListItem>Please select a model</asp:ListItem>
<asp:ListItem Value="18295">Impreza</asp:ListItem>
<asp:ListItem Value="26595">WRX</asp:ListItem>
<asp:ListItem Value="21595">Crosstrek</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlpromocars" runat="server" AutoPostBack="True" Visible="False">
<asp:ListItem>Please select a model</asp:ListItem>
<asp:ListItem Value="25395">BRZ</asp:ListItem>
<asp:ListItem Value="24995">Outback</asp:ListItem>
春季促销活动
Protected Sub chkpromo_CheckedChanged(sender As Object, e As EventArgs) Handles chkpromo.CheckedChanged
If chkpromo.Checked = True Then
ddlcars.Visible = False & ddlpromocars.Visible = True
Exit Sub
End If
If chkpromo.Checked = False Then
ddlcars.Visible = True & ddlpromocars.Visible False
Exit Sub
End If
End Sub
答案 0 :(得分:0)
删除Autopostback =&#34; True&#34;对于chkpromo,ddlcars和ddlpromocars来避免回发
删除Visible =&#34; False&#34;对于ddlcars和ddlpromocars来写html但是用css类隐藏它。
删除OnCheckedChanged =&#34; chkpromo_CheckedChanged&#34;为chkpromo避免回发
然后尝试
git push --set-upstream origin master
最后从Sub&#34; chkpromo_CheckedChanged&#34;后面的代码中删除。
答案 1 :(得分:0)
受保护的子chkPromo_CheckedChanged(发件人为对象,e为EventArgs)处理chkPromo.CheckedChanged
If chkPromo.Checked = True Then
ddlpromocars.visible = True
ddlcars.Visible = False
End If
If chkPromo.Checked = False Then
ddlpromocars.Visible = False
ddlcars.Visible = True
End If
End Sub