Repeater - Conditional Binding

  • Thread starter Thread starter Mick Walker
  • Start date Start date
M

Mick Walker

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
 
Mick Walker said:
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
 
Back
Top