conditional DataFieldText when DataBinding

G

Guest

Hi

I'm using a Metabuilders checked list box to create a list of contacts on my
page. Each contact has a FirstName, Surname, and Company. Except that some
might not have an entry for Company, or for First/Surname.

How do I use Databinding and yet say "if theres nothing in Company, show
Firstname/Surname, otherwise show Company".

Any ideas on this?!

Cheers


Dan
 
J

Jc Morin

Hi Dan,

Don't use datasource and databind method then (those are shortcut and can't
apply to case like you)

Do a for loop in every item and add them 1 by 1 to the checkbox list. (the
databind do pretty much the same stuff anyway)

Something like this

For Each member As MemberOfAspDotNet In yourList
If IsNothing(member.company) Then
CheckBoxList1.Items.Add(New ListItem(member.First & " " &
member.Last, member.id))
Else
CheckBoxList1.Items.Add(New ListItem(member.company, member.id))
End If
Next

Hope that help.
 
G

Guest

Thanks JC!

Jc Morin said:
Hi Dan,

Don't use datasource and databind method then (those are shortcut and can't
apply to case like you)

Do a for loop in every item and add them 1 by 1 to the checkbox list. (the
databind do pretty much the same stuff anyway)

Something like this

For Each member As MemberOfAspDotNet In yourList
If IsNothing(member.company) Then
CheckBoxList1.Items.Add(New ListItem(member.First & " " &
member.Last, member.id))
Else
CheckBoxList1.Items.Add(New ListItem(member.company, member.id))
End If
Next

Hope that help.
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top