1

好的,所以我试图获得一个下拉菜单来取消隐藏在选择特定索引时隐藏的一些 div。我知道需要更改内联样式,但不知道如何使用背面控件来执行它。

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master"
CodeBehind="Estimation.aspx.vb" Inherits="CIS212FinalProjectASPportion.WebForm1" %>
<body Id="mainBody" runat="server">
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="EstimationSelection">
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                <asp:ListItem>Select Value</asp:ListItem>
                <asp:ListItem>Lawn Care</asp:ListItem>
                <asp:ListItem>Plowing</asp:ListItem>
                <asp:ListItem>Both</asp:ListItem>
            </asp:DropDownList>
            <br />
</div>

<div id="UserInfo" style="display: none;">
    <asp:Label ID="firstName" runat="server" Text="Label">First Name &nbsp;</asp:Label>
    <input id="Text1" type="text" />
    <asp:Label ID="lastName" runat="server" Text="Label">Last Name &nbsp;</asp:Label>
    <input id="Text2" type="text" /> <br />
    <asp:Label ID="address" runat="server" Text="Label">Address       &nbsp&nbsp;&nbsp;&nbsp;&nbsp;</asp:Label>
    <input id="Text3" type="text" />
    <asp:Label ID="city" runat="server" Text="Label">City &nbsp;</asp:Label>
    <input id="Text4" type="text" /><br />
    <asp:Label ID="state" runat="server" Text="Label">State&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</asp:Label>
    <input id="Text5" type="text" />
    <asp:Label ID="zipCode" runat="server" Text="Label">Zip Code &nbsp;</asp:Label>
    <input id="Text6" type="text" /> <br />
    <asp:Label ID="emailAddress" runat="server" Text="Label">Email Address &nbsp;</asp:Label>
    <input id="Text7" type="text" />
</div>
</body>
</asp:Content>

然后现在对于我拥有的背面代码

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
    If DropDownList1.SelectedIndex(1) Then
         Me.Body.Div.UserInfo.Style.add("display", "block")
        ' set div id="LawnCare" style="display: block;"
    End If
End Sub

Option Explicit 和 Strict 都打开。

4

1 回答 1

0

试试这样…………

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
  Dim oPanel As Panel
  oPanel = Me.FindControl("UserInfo")
  If DropDownList1.SelectedIndex = 1 Then
    oPanel.Visible = True
  Else
    oPanel.Visible = False
  End If
  oPanel = Nothing
End Sub


<div id="EstimationSelection">
  <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
    <asp:ListItem>Select Value</asp:ListItem>
    <asp:ListItem>Lawn Care</asp:ListItem>
    <asp:ListItem>Plowing</asp:ListItem>
    <asp:ListItem>Both</asp:ListItem>
  </asp:DropDownList>
  <br />
</div>

<asp:Panel id="UserInfo" Visible="false" runat="server">
  <asp:Label ID="firstName" runat="server" Text="Label">First Name</asp:Label>
    <input id="Text1" type="text" />
  <asp:Label ID="lastName" runat="server" Text="Label">Last Name</asp:Label>
    <input id="Text2" type="text" /> <br />
  <asp:Label ID="address" runat="server" Text="Label">Address</asp:Label>
    <input id="Text3" type="text" />
  <asp:Label ID="city" runat="server" Text="Label">City</asp:Label>
    <input id="Text4" type="text" /><br />
  <asp:Label ID="state" runat="server" Text="Label">State</asp:Label>
    <input id="Text5" type="text" />
  <asp:Label ID="zipCode" runat="server" Text="Label">Zip Code</asp:Label>
    <input id="Text6" type="text" /> <br />
  <asp:Label ID="emailAddress" runat="server" Text="Label">Email Address</asp:Label>
    <input id="Text7" type="text" />
</asp:Panel>

基本上我将您的客户端 DIV 更改为服务器端 PANEL

于 2013-01-10T01:04:25.907 回答