IF statement

Discussion in 'ASP .Net' started by simon, Sep 22, 2004.

  1. simon

    simon Guest

    I have dataRepeater.
    If the column "exists" from the database is True then I would like to show
    the link button, if the value is False I would like to show only the name in
    label.
    Something like this:

    <ItemTemplate>
    <%# IF Container.DataItem( "exists" ) =true then '%>
    <asp:LinkButton CausesValidation=False CommandArgument='<%#
    DataBinder.Eval(Container.DataItem,"tAdv_ID")%>
    CommandName="AdvType" Runat="server" ID="lnkAdvType">
    <%# DataBinder.Eval(Container.DataItem,"tadv_name") %>
    </asp:LinkButton>
    <%# else %>
    <asp:label runat=server id=lblName Text='<%#
    DataBinder.Eval(Container.DataItem, "tadv_name") %>'></asp:label>
    <%# end if%>
    </ItemTemplate>

    What is the proper way to do that?

    Thank you,
    Simon
    simon, Sep 22, 2004
    #1
    1. Advertising

  2. simon

    simon Guest

    thank you. I know for this option.
    But what if the example is more complicated and I need to use if statement.

    Or with other words, how you can use IF statements here in asp.net or that
    is not practice here and there is some workaround?

    Thank you,
    Simon

    "Eliyahu Goldin" <> wrote in message
    news:...
    > Simon,
    >
    > No if statement.
    >
    > Have in your itemtempate both the link button and the label one next to
    > another. Databind Visible property of both of them to the value of the
    > column "exists". For the label negate the value.
    >
    > Eliyahu
    >
    > "simon" <> wrote in message
    > news:%...
    > > I have dataRepeater.
    > > If the column "exists" from the database is True then I would like to

    show
    > > the link button, if the value is False I would like to show only the

    name
    > in
    > > label.
    > > Something like this:
    > >
    > > <ItemTemplate>
    > > <%# IF Container.DataItem( "exists" ) =true then '%>
    > > <asp:LinkButton CausesValidation=False CommandArgument='<%#
    > > DataBinder.Eval(Container.DataItem,"tAdv_ID")%>
    > > CommandName="AdvType" Runat="server" ID="lnkAdvType">
    > > <%# DataBinder.Eval(Container.DataItem,"tadv_name")

    %>
    > > </asp:LinkButton>
    > > <%# else %>
    > > <asp:label runat=server id=lblName Text='<%#
    > > DataBinder.Eval(Container.DataItem, "tadv_name") %>'></asp:label>
    > > <%# end if%>
    > > </ItemTemplate>
    > >
    > > What is the proper way to do that?
    > >
    > > Thank you,
    > > Simon
    > >
    > >

    >
    >
    simon, Sep 22, 2004
    #2
    1. Advertising

  3. Simon,

    No if statement.

    Have in your itemtempate both the link button and the label one next to
    another. Databind Visible property of both of them to the value of the
    column "exists". For the label negate the value.

    Eliyahu

    "simon" <> wrote in message
    news:%...
    > I have dataRepeater.
    > If the column "exists" from the database is True then I would like to show
    > the link button, if the value is False I would like to show only the name

    in
    > label.
    > Something like this:
    >
    > <ItemTemplate>
    > <%# IF Container.DataItem( "exists" ) =true then '%>
    > <asp:LinkButton CausesValidation=False CommandArgument='<%#
    > DataBinder.Eval(Container.DataItem,"tAdv_ID")%>
    > CommandName="AdvType" Runat="server" ID="lnkAdvType">
    > <%# DataBinder.Eval(Container.DataItem,"tadv_name") %>
    > </asp:LinkButton>
    > <%# else %>
    > <asp:label runat=server id=lblName Text='<%#
    > DataBinder.Eval(Container.DataItem, "tadv_name") %>'></asp:label>
    > <%# end if%>
    > </ItemTemplate>
    >
    > What is the proper way to do that?
    >
    > Thank you,
    > Simon
    >
    >
    Eliyahu Goldin, Sep 22, 2004
    #3
  4. Simon,

    If you need more complex processing, you should do it in code-behind in
    ItemDataBound event.

    Eliyahu

    "simon" <> wrote in message
    news:...
    > thank you. I know for this option.
    > But what if the example is more complicated and I need to use if

    statement.
    >
    > Or with other words, how you can use IF statements here in asp.net or that
    > is not practice here and there is some workaround?
    >
    > Thank you,
    > Simon
    >
    > "Eliyahu Goldin" <> wrote in message
    > news:...
    > > Simon,
    > >
    > > No if statement.
    > >
    > > Have in your itemtempate both the link button and the label one next to
    > > another. Databind Visible property of both of them to the value of the
    > > column "exists". For the label negate the value.
    > >
    > > Eliyahu
    > >
    > > "simon" <> wrote in message
    > > news:%...
    > > > I have dataRepeater.
    > > > If the column "exists" from the database is True then I would like to

    > show
    > > > the link button, if the value is False I would like to show only the

    > name
    > > in
    > > > label.
    > > > Something like this:
    > > >
    > > > <ItemTemplate>
    > > > <%# IF Container.DataItem( "exists" ) =true then '%>
    > > > <asp:LinkButton CausesValidation=False CommandArgument='<%#
    > > > DataBinder.Eval(Container.DataItem,"tAdv_ID")%>
    > > > CommandName="AdvType" Runat="server" ID="lnkAdvType">
    > > > <%#

    DataBinder.Eval(Container.DataItem,"tadv_name")
    > %>
    > > > </asp:LinkButton>
    > > > <%# else %>
    > > > <asp:label runat=server id=lblName Text='<%#
    > > > DataBinder.Eval(Container.DataItem, "tadv_name") %>'></asp:label>
    > > > <%# end if%>
    > > > </ItemTemplate>
    > > >
    > > > What is the proper way to do that?
    > > >
    > > > Thank you,
    > > > Simon
    > > >
    > > >

    > >
    > >

    >
    >
    Eliyahu Goldin, Sep 22, 2004
    #4
  5. You don't need an if statement. If you want some complex logic, encapsulate
    it in a property (get method), and use that.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    I get paid good money to
    solve puzzles for a living

    "simon" <> wrote in message
    news:...
    > thank you. I know for this option.
    > But what if the example is more complicated and I need to use if

    statement.
    >
    > Or with other words, how you can use IF statements here in asp.net or that
    > is not practice here and there is some workaround?
    >
    > Thank you,
    > Simon
    >
    > "Eliyahu Goldin" <> wrote in message
    > news:...
    > > Simon,
    > >
    > > No if statement.
    > >
    > > Have in your itemtempate both the link button and the label one next to
    > > another. Databind Visible property of both of them to the value of the
    > > column "exists". For the label negate the value.
    > >
    > > Eliyahu
    > >
    > > "simon" <> wrote in message
    > > news:%...
    > > > I have dataRepeater.
    > > > If the column "exists" from the database is True then I would like to

    > show
    > > > the link button, if the value is False I would like to show only the

    > name
    > > in
    > > > label.
    > > > Something like this:
    > > >
    > > > <ItemTemplate>
    > > > <%# IF Container.DataItem( "exists" ) =true then '%>
    > > > <asp:LinkButton CausesValidation=False CommandArgument='<%#
    > > > DataBinder.Eval(Container.DataItem,"tAdv_ID")%>
    > > > CommandName="AdvType" Runat="server" ID="lnkAdvType">
    > > > <%#

    DataBinder.Eval(Container.DataItem,"tadv_name")
    > %>
    > > > </asp:LinkButton>
    > > > <%# else %>
    > > > <asp:label runat=server id=lblName Text='<%#
    > > > DataBinder.Eval(Container.DataItem, "tadv_name") %>'></asp:label>
    > > > <%# end if%>
    > > > </ItemTemplate>
    > > >
    > > > What is the proper way to do that?
    > > >
    > > > Thank you,
    > > > Simon
    > > >
    > > >

    > >
    > >

    >
    >
    Kevin Spencer, Sep 22, 2004
    #5
    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. Replies:
    3
    Views:
    798
  2. Jay McGavren
    Replies:
    11
    Views:
    1,125
    Alan Krueger
    Jan 16, 2006
  3. tedsuzman
    Replies:
    2
    Views:
    7,074
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  4. Ted
    Replies:
    1
    Views:
    460
    Duncan Booth
    Jul 22, 2004
  5. Replies:
    21
    Views:
    1,050
    Giannis Papadopoulos
    Aug 2, 2005
Loading...

Share This Page