Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何隐藏html列表项<;李>;使用代码隐藏中的c#_C#_Asp.net_C# 4.0_Code Behind - Fatal编程技术网

如何隐藏html列表项<;李>;使用代码隐藏中的c#

如何隐藏html列表项<;李>;使用代码隐藏中的c#,c#,asp.net,c#-4.0,code-behind,C#,Asp.net,C# 4.0,Code Behind,我想用C#隐藏作为“li”标记的html列表项。但我不能这么做。在前面的文章中,我只是使用c#隐藏DIV标记。但我无法隐藏“li”标签。请帮我做这件事。如果你能发送你的详细解释 这是我的部分代码: this.hide.style.Add("display", "none"); // Error in hide 这是我的html代码: <li ID="hide" style="display: Block;"><a href="../list.aspx" >l

我想用C#隐藏作为“li”标记的html列表项。但我不能这么做。在前面的文章中,我只是使用c#隐藏DIV标记。但我无法隐藏“li”标签。请帮我做这件事。如果你能发送你的详细解释

这是我的部分代码:

  this.hide.style.Add("display", "none");  // Error in hide 
这是我的html代码:

  <li ID="hide" style="display: Block;"><a href="../list.aspx" >list Approval</a></li>
  • 请帮助我解决此问题。…

    
    
    <asp:Panel ID="Panel1" runat="server">
         <div >
            //place here your list
        </div>
     </asp:Panel>
    
    //把你的名单放在这里

    使用c#可以隐藏面板

    您可以通过将runat='Server'属性添加到标记来访问Html项目,然后可以通过编程方式访问该项目,就像访问“普通”ASP.Net UI控件一样

    <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");  
    
  • HtmlGenericControl listItem=this.hide作为HtmlGenericControl; 如果(listItem!=null) this.hide.style.Add(“display”、“none”);
    id
    runat=“server”
    添加到列表项中:

  • 从代码隐藏设置可见性属性(C#示例):

    也可以使用此方法应用/删除样式:

    if (someBool)
    {
        fooItem.Attributes.Add("class", "foobar");
        // or removing a style 
        foobarItem.Attributes.Remove("class");
    }
    
    请记住将“using System.Web.UI.HtmlControls;”添加到using
    if (someBool)
    {
        fooItem.Attributes.Add("class", "foobar");
        // or removing a style 
        foobarItem.Attributes.Remove("class");
    }