Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to hide html list item that is "li" tag using C#. But i can't do this. In earlier i just hide DIV tag using c#. But i can't hide "li" tag. Please help me to do this .If you can please send your detail Explanation...

This is my partial 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 to solve this issue ....

like image 762
Fernando Avatar asked Mar 09 '12 10:03

Fernando


2 Answers

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");
}
like image 180
GDB Avatar answered Oct 05 '22 13:10

GDB


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");  
like image 28
Lloyd Avatar answered Oct 05 '22 11:10

Lloyd