[英]Div style changing using asp.net C# code
<div runat="server" class="labels" style="display:none; height: 100%; font-family: 'Segoe UI';">
<asp:Label ID="Label4" runat="server" Text="Description:" Font-Bold="True"></asp:Label>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label5" runat="server" Text="Impact:" Font-Bold="True"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label6" runat="server" Text="Recommendation:" Font-Bold="True"></asp:Label>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br /><br />
</div>
我想將樣式更改為display:true,因為它在顯示上是已知的:none,我想使用c#代碼完成它。 如何調用類名並更改其樣式/屬性...
首先像這樣給你的div一個ID
<div runat="server" id="div1"></div>
然后在您的C#代碼中編寫此代碼以向div添加樣式。
string style = div1.Style[HtmlTextWriterStyle.Display];
if(style.ToLower()=="none")
div1.Style.Add(HtmlTextWriterStyle.Display, "block");
這是刪除樣式的方法。
div1.Style.Remove(HtmlTextWriterStyle.Display);
<% var display = "block";
if(isHidden){
display = "none";
}
%>
<div runat="server" class="labels" style="display:<%=display%>; height: 100%; font-family: 'Segoe UI';">
<asp:Label ID="Label4" runat="server" Text="Description:" Font-Bold="True"></asp:Label>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label5" runat="server" Text="Impact:" Font-Bold="True"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="Label6" runat="server" Text="Recommendation:" Font-Bold="True"></asp:Label>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br /><br />
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.