如何隐藏html列表项<;李>;从代码背后使用c
本文关键字:gt 代码 背后 何隐藏 lt 隐藏 html 列表 | 更新日期: 2023-09-27 18:27:10
我想用C#隐藏"li"标记的html列表项。但我做不到。在前面,我只是使用c隐藏DIV标记。但我无法隐藏"李"标签。请帮我做这件事。如果你能把你的详细说明发给。。。
这是我的部分代码:
this.hide.style.Add("display", "none"); // Error in hide
这是我的html代码:
<li ID="hide" style="display: Block;"><a href="../list.aspx" >list Approval</a></li>
请帮我解决这个问题。。。。
将id
和runat="server"
添加到您的列表项:
<li id="fooItem" runat="server">
<%-- ... --%>
</li>
从代码隐藏设置可见性属性(C#示例):
if (someBool)
{
fooItem.Visible = false;
}
您也可以使用这种方法来应用/删除样式:
if (someBool)
{
fooItem.Attributes.Add("class", "foobar");
// or removing a style
foobarItem.Attributes.Remove("class");
}
您可以通过将runat='Server'属性添加到标记来访问作为GenericHtmlControl的Html项,然后您可以像访问"普通"ASP.Net UI控件一样以编程方式访问属性。
<li ID="hide" style="display: Block;" runat="Server"><a href="../list.aspx" >list Approval</a></li>
HtmlGenericControl listItem = this.hide as HtmlGenericControl;
if (listItem != null)
this.hide.style.Add("display", "none");
<asp:Panel ID="Panel1" runat="server">
<div >
//place here your list
</div>
</asp:Panel>
使用c#可以隐藏面板