DataBinding ListBox.DataTextField

G

Guest

Hi guys

I have an asp:ListBox on my form, which I'm populating with a DataReader,
using DataSource/DataBind.

The problem is that the main field I want to use for DataTextField,
"Company" in this case, is often blank. How can I get the DataBinding to
go...

"if Company is blank, use ContactName, else use Company"

...is that even possible? Or is there a way I can do this in the SQL somehow?

Hope that makes sense!

Cheers



Dan
 
E

Eliyahu Goldin

Dan,

You can do it in the select:

select ... case Company when null then ContactName else Company end as
CompanyName...

Eliyahu
 
S

Steven Cheng[MSFT]

Hi Dan,

ListBox is a simple databound control which doesn't support itemdatabound
event like repeater or datalist. So if you want to do it in ASP.NET layer,
you can consider programmtically loop through the datareader and populate
the listbox instead of using databinding. Also, for T-SQL layer, you can
have a look at Eliyahu's suggestion and you can also try posting in
SQLServer. programming newsgroup since there're many experiences SQL guys
there.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top