how can i hide html list item <li> using c# from code behind

筅森魡賤 提交于 2019-12-05 14:05:06
GDB

Add an id and runat="server" to your list item:

<li id="fooItem" runat="server">
    <%-- ... --%>
</li>

Set the visibility property from code behind (C# example):

if (someBool)
{
    fooItem.Visible = false;
}

You can also use this approach for applying/removing a style:

if (someBool)
{
    fooItem.Attributes.Add("class", "foobar");
    // or removing a style 
    foobarItem.Attributes.Remove("class");
}

You can access a Html item as a GenericHtmlControl by adding the runat='Server' attribute to the markup, you can then access the properties programatically as if it were a "normal" ASP.Net UI control.

<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>

and with c# you can hide a panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!