DataBinding ListBox.DataTextField

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Dan,

You can do it in the select:

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

Eliyahu
 
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.)
 
Back
Top