Repeater - Conditional Binding

Discussion in 'ASP .Net' started by Mick Walker, Sep 15, 2007.

  1. Mick Walker

    Mick Walker Guest

    Hi Everyone,

    I am binding my repeater from a Paged Data source I populate in my code
    behind.

    I am wondering How do I set some default text if a value is null (or a
    empty string)

    I am currently using the format:

    <tr class="RowStyle">
    <td style="width: 100px">
    Age:
    </td>
    <td style="width: 100px">
    <%#Eval("Age").ToString() %>
    </td>
    <tr/>

    So if the age field is blank or null, I would like to display some
    default text such as "None Specified"

    Regards
    Mick
    --
    Contact Me: perl -e 'printf "%silto%c%sker%ccodegurus%corg%c", "ma", 58,
    "mwal", 64, 46, 10;'
    A man's own good breeding is the best security against other people's
    ill manners.
    Mick Walker, Sep 15, 2007
    #1
    1. Advertising

  2. Mick Walker

    Lloyd Sheen Guest

    "Mick Walker" <> wrote in message
    news:...
    > Hi Everyone,
    >
    > I am binding my repeater from a Paged Data source I populate in my code
    > behind.
    >
    > I am wondering How do I set some default text if a value is null (or a
    > empty string)
    >
    > I am currently using the format:
    >
    > <tr class="RowStyle">
    > <td style="width: 100px">
    > Age:
    > </td>
    > <td style="width: 100px">
    > <%#Eval("Age").ToString() %>
    > </td>
    > <tr/>
    >
    > So if the age field is blank or null, I would like to display some default
    > text such as "None Specified"
    >
    > Regards
    > Mick
    > --
    > Contact Me: perl -e 'printf "%silto%c%sker%ccodegurus%corg%c", "ma", 58,
    > "mwal", 64, 46, 10;'
    > A man's own good breeding is the best security against other people's ill
    > manners.


    One way to do this is to handle the ItemDataBound event. This will give you
    a chance to put whatever value you want as the text if the age is blank or
    null. Check the information passed to the event in the "ByVal e As
    System.Web.UI.WebControls.RepeaterItemEventArgs" which will give you access
    to the controls and to the data item that is being bound.

    Hope this helps
    Lloyd Sheen
    Lloyd Sheen, Sep 15, 2007
    #2
    1. Advertising

  3. Mick Walker

    bruce barker Guest

    <%# (Eval("Age") ?? "Unknown Age").ToString() %>


    -- bruce (sqlwork.com)

    Mick Walker wrote:
    > Hi Everyone,
    >
    > I am binding my repeater from a Paged Data source I populate in my code
    > behind.
    >
    > I am wondering How do I set some default text if a value is null (or a
    > empty string)
    >
    > I am currently using the format:
    >
    > <tr class="RowStyle">
    > <td style="width: 100px">
    > Age:
    > </td>
    > <td style="width: 100px">
    > <%#Eval("Age").ToString() %>
    > </td>
    > <tr/>
    >
    > So if the age field is blank or null, I would like to display some
    > default text such as "None Specified"
    >
    > Regards
    > Mick
    bruce barker, Sep 15, 2007
    #3
    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. syd
    Replies:
    0
    Views:
    371
  2. =?Utf-8?B?UmFzaWthIFdJSkFZQVJBVE5F?=

    Repeater, conditional logic

    =?Utf-8?B?UmFzaWthIFdJSkFZQVJBVE5F?=, May 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,786
    =?Utf-8?B?UmFzaWthIFdJSkFZQVJBVE5F?=
    May 13, 2005
  3. Alec S.
    Replies:
    10
    Views:
    10,142
    Alec S.
    Apr 16, 2005
  4. =?Utf-8?B?RGFiYmxlcg==?=

    conditional in GridView Eval binding?

    =?Utf-8?B?RGFiYmxlcg==?=, Jun 27, 2006, in forum: ASP .Net
    Replies:
    8
    Views:
    46,763
    april198474
    Sep 22, 2009
  5. Peter Morris

    Conditional output in Repeater?

    Peter Morris, Mar 19, 2008, in forum: ASP .Net
    Replies:
    5
    Views:
    555
    bruce barker
    Mar 19, 2008
Loading...

Share This Page