Repeater - Conditional Binding

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
 
L

Lloyd Sheen

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top