Hide when Empty. How to do this?

Discussion in 'ASP .Net' started by Shapper, Jun 17, 2005.

  1. Shapper

    Shapper Guest

    Hello,

    I have this code line inside an ASP.Net Repeater:
    <a href='<%# DataBinder.Eval(Container.DataItem, "link") %>'><%=
    readMore %></a>

    What I need to do is:
    1. Show readMore value if <%# DataBinder.Eval(Container.DataItem,
    "link") %> is not empty.

    2. Show nothing if <%# DataBinder.Eval(Container.DataItem, "link") %> is
    empty.

    In this moment it is showing all the time the value of readMore.

    Or maybe just hide the <a> tag.

    Is this possible?

    Thanks,
    Miguel
     
    Shapper, Jun 17, 2005
    #1
    1. Advertising

  2. Shapper

    Dave Fancher Guest

    Both Azat and Gregory gave good possible solutions for this the last time
    you asked. Personally, I'd prefer to filter out the rows where the value is
    "empty" but if your solution doesn't allow for that, you can
    programmatically hide the link during the ItemDataBound event
    (http://msdn.microsoft.com/library/d...bcontrolsrepeaterclassitemdataboundtopic.asp).

    If you want to hide it by setting the link's Visible property to false or by
    appending a display: none to its class attribute is up to you. Of course,
    in order to access the link from the event handler, you'll have to either
    set Runat="Server" on the link OR switch to using <asp:hyperlink ...>.
    You'll also want to give the control an ID so you can easily access it
    through FindControl().

    HTH
    ----------------
    Dave Fancher
    http://www.davefancher.com

    "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
    news:...
    > Hello,
    >
    > I have this code line inside an ASP.Net Repeater:
    > <a href='<%# DataBinder.Eval(Container.DataItem, "link") %>'><%= readMore
    > %></a>
    >
    > What I need to do is:
    > 1. Show readMore value if <%# DataBinder.Eval(Container.DataItem, "link")
    > %> is not empty.
    >
    > 2. Show nothing if <%# DataBinder.Eval(Container.DataItem, "link") %> is
    > empty.
    >
    > In this moment it is showing all the time the value of readMore.
    >
    > Or maybe just hide the <a> tag.
    >
    > Is this possible?
    >
    > Thanks,
    > Miguel
    >
     
    Dave Fancher, Jun 17, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,047
    Klaus Johannes Rusch
    Jul 16, 2003
  2. Lukas
    Replies:
    3
    Views:
    837
    spiff
    Nov 10, 2005
  3. BB
    Replies:
    3
    Views:
    5,848
  4. GridView Hide empty row (vb)

    , Jun 19, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    1,208
  5. Empty results hide GridView headers

    , Oct 23, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    670
    David Thielen
    Oct 24, 2006
Loading...

Share This Page