如何隐藏html列表项<;李>;使用代码隐藏中的c#
我想用C#隐藏作为“li”标记的html列表项。但我不能这么做。在前面的文章中,我只是使用c#隐藏DIV标记。但我无法隐藏“li”标签。请帮我做这件事。如果你能发送你的详细解释 这是我的部分代码:如何隐藏html列表项<;李>;使用代码隐藏中的c#,c#,asp.net,c#-4.0,code-behind,C#,Asp.net,C# 4.0,Code Behind,我想用C#隐藏作为“li”标记的html列表项。但我不能这么做。在前面的文章中,我只是使用c#隐藏DIV标记。但我无法隐藏“li”标签。请帮我做这件事。如果你能发送你的详细解释 这是我的部分代码: this.hide.style.Add("display", "none"); // Error in hide 这是我的html代码: <li ID="hide" style="display: Block;"><a href="../list.aspx" >l
this.hide.style.Add("display", "none"); // Error in hide
这是我的html代码:
<li ID="hide" style="display: Block;"><a href="../list.aspx" >list Approval</a></li>
请帮助我解决此问题。…
<asp:Panel ID="Panel1" runat="server">
<div >
//place here your list
</div>
</asp:Panel>
//把你的名单放在这里
使用c#可以隐藏面板您可以通过将runat='Server'属性添加到标记来访问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");
HtmlGenericControl listItem=this.hide作为HtmlGenericControl;
如果(listItem!=null)
this.hide.style.Add(“display”、“none”);
将id
和runat=“server”
添加到列表项中:
从代码隐藏设置可见性属性(C#示例):
也可以使用此方法应用/删除样式:
if (someBool)
{
fooItem.Attributes.Add("class", "foobar");
// or removing a style
foobarItem.Attributes.Remove("class");
}
请记住将“using System.Web.UI.HtmlControls;”添加到using
if (someBool)
{
fooItem.Attributes.Add("class", "foobar");
// or removing a style
foobarItem.Attributes.Remove("class");
}