如何使用代码隐藏的c#隐藏html列表项
我想隐藏使用C#的“li”标签的html列表项。 但我不能这样做。 在早些时候我只是使用c#隐藏DIV标签。 但我无法隐藏“li”标签。 请帮我这样做。如果可以,请发送您的详细说明……
这是我的部分代码:
this.hide.style.Add("display", "none"); // Error in hide
这是我的HTML代码:
list Approval
请帮我解决这个问题….
将id
和runat="server"
到列表项:
<%-- ... --%>
从后面的代码设置visibility属性(C#示例):
if (someBool) { fooItem.Visible = false; }
您还可以使用此方法来应用/删除样式:
if (someBool) { fooItem.Attributes.Add("class", "foobar"); // or removing a style foobarItem.Attributes.Remove("class"); }
您可以通过将runat =’Server’属性添加到标记来访问Html项目作为GenericHtmlControl ,然后您可以以编程方式访问属性 ,就好像它是“正常”的ASP.Net UI控件一样。
list Approval HtmlGenericControl listItem = this.hide as HtmlGenericControl; if (listItem != null) this.hide.style.Add("display", "none");
//place here your list
使用c#,您可以隐藏面板