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

+4
source share
3 answers

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"); } 
+15
source

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"); 
+4
source
 <asp:Panel ID="Panel1" runat="server"> <div > //place here your list </div> </asp:Panel> 

and with C # you can hide the panel

0
source

Source: https://habr.com/ru/post/1400552/


All Articles