How can I hide the html <li> list item using C # from code
I want to hide the html list item which is the "li" tag using C #. But I canβt do it. I used to just hide the DIV tag using C #. But I can not hide the tag "li". Please help me do this. If you can send your item Explanation ...
This is my incomplete code:
this.hide.style.Add("display", "none"); // Error in hide This is my html code:
<li ID="hide" style="display: Block;"><a href="../list.aspx" >list Approval</a></li> Please help me solve this problem ....
Add id and runat="server" to the list item:
<li id="fooItem" runat="server"> <%-- ... --%> </li> Set the visibility property from the code behind (C # example):
if (someBool) { fooItem.Visible = false; } You can also use this approach to apply / remove a style:
if (someBool) { fooItem.Attributes.Add("class", "foobar"); // or removing a style foobarItem.Attributes.Remove("class"); } You can access the Html element as a GenericHtmlControl by adding the runat = 'Server' attribute to the markup, then you can access the property programmatically, as if it were the normal ASP.Net user interface.
<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");