473,503 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataBinding ListBox.DataTextField

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
Apr 3 '06 #1
2 2177
Dan,

You can do it in the select:

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

Eliyahu

"musosdev" <mu*******@community.nospam> wrote in message
news:2F**********************************@microsof t.com...
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

Apr 3 '06 #2
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.)

Apr 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3296
by: J. Babe | last post by:
I am trying to bind data from a database to a DropDownListBox on an ..aspx page. I want to display 2 fields in listbox (listbox's .DataTextField = two fields in the database "Employee.FName" & "...
1
2220
by: oafyuf | last post by:
Hi, I'm trying to learn ASP.NET by doing a pilot project: I have a DataGrid which contains a nested DataList. I want to iterate through the SQLDataReader for the DataGrid and populate each...
2
1211
by: Ben Mann | last post by:
Hi There, Ive got an ASP .Net page with a listbox element. This listbox element is databound to a sorted list filled with keys and values from the database: dbReader =...
1
3990
by: Ray Valenti | last post by:
I have a ASP listbox that I am trying to populate with two fields, one for display (Category) and one to store (ID) as the selected item. I can successfully populate and view the list. How ever...
3
4775
by: Joey | last post by:
Hi, I'm trying to add a default item to my listbox but when I do it tells me that it's not defined, could someone tell me the syntax I need to use to get the listbox control to display a default...
5
3513
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
4
4189
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox),...
5
1045
by: serge calderara | last post by:
Dear all, I try to bind a particular column from a dataset to a listbox What I am doing wrong in the following code ? There is no error return but listbox is empty Dim ds As New Data.DataSet
6
2327
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am...
0
7091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1516
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.