gpt4 book ai didi

asp.net - 通过asp.net控件修改css显示

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:27 25 4
gpt4 key购买 nike

好的,所以我正在尝试获取一个下拉菜单来取消隐藏我在选择特定索引时隐藏的一些 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 都打开。

最佳答案

试试这样............

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

关于asp.net - 通过asp.net控件修改css显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14179825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com