Setting the visible property of a list item

Posted on 2004-10-29
Last Modified: 2008-03-17
Hi, I have an <ul> which has several <li> inside. My question is: How do I hide / show a specific <li> without creating one <ul> for one <li>, putting the <ul> inside a panel and setting the visible property of that panel?
Question by:James_fl
    LVL 28

    Assisted Solution

    Hi James_fl,

    have you tried useing Literal control
    create literal control for each <li>, and add this <li> inside the control
    create <ul>

        <asp:Literal Text="<li>your text</li>" id="li1" runat="server" />
        <asp:Literal Text="<li>your text</li>" id="li2" runat="server" />

    and then hide and show the literals


    Author Comment

    thanks for answering mmarinov.

    I need to put a link button on the list. If I put an <asp:linkbutton> tag inside the text attribute, will it render properly?


    Author Comment

    so it will be like this:

    <asp:Literal id="li1" runat="server" Text="<li><asp:linkbutton id=""btn"" runat=""server"">Link 1</asp:linkbutton></li>"

    If I do that, can I manipulate the btn in Visual Studio?
    LVL 28

    Expert Comment

    i don't think so
    the Text property can accept and render only pure html
    i've checked and saw ( i didn't know that it is possible )
    <ul runat="server" id="as">
      <li runat="server" id="as2">assa
        <asp:HyperLink Runat="server" NavigateUrl="asss" id="we">123</asp:HyperLink></li></ul>

    LVL 15

    Expert Comment

    Are you trying to programmatically decide, from the code-behind file, which <li> elements to display or not display?

    Or are you trying to provide the ability to hide/show <li> elements dynamically within the browser (without PostBack) based on some user actions?
    LVL 15

    Accepted Solution

    If it's the former (display or not from code-behind code), then why not something simple like:

            <li runat="server" id="li1">Item #1</li>
            <li runat="server" id="li2">Item #2</li>
            <li runat="server" id="li3">Item #3</li>

    And then, in the code-behind file, you'd have:

        protected HtmlGenericControl li1;
        protected HtmlGenericControl li2;
        protected HtmlGenericControl li3;

    and wherever you want to make the show-or-not-show decisions

        li1.Visible = true;
        li2.Visible = false;
        li3.Visible = true;

    Author Comment

    Thogek, your solution works. thanks..

    mmarinov, I tried your second solution but it didn't work since it can't find the control. But since your first solution works and it actually answered my question (my fault for not asking specifically), I'll give you also a portion of the point

    MOD, please split the point and give 100 point to mmarinov.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now