473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataBinding ListBox.DataTex tField

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 2180
Dan,

You can do it in the select:

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

Eliyahu

"musosdev" <mu*******@comm unity.nospam> wrote in message
news:2F******** *************** ***********@mic rosoft.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
3300
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" & " " & "Employee.LName" - space in between the names) and also have the listbox's .DataValueField = Employee.EmployeeID field.
1
2223
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 DataList by binding to a fresh SQLDataReader. At the moment I can only bind to the first instance of the DataList. If I could bind the data by the...
2
1212
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 = lookupUtil.getLookup("country", 0, 0, ConfigurationSettings.AppSettings("DSN")) If dbReader.HasRows Then
1
4000
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 after specifying the field to hold the selected value with the Databindings property, the error below show up. VS changes the DataSource from...
3
4778
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 item? I have tried the following: lstStates.Items.Insert(0, new ListItem("By State","0"))
5
3517
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 selected items of that listbox and display it. can anyone help? Thanks
4
4199
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), SqlConnection (sqlConnection), SqlDataAdapter (daLookupData), SqlDataAdapter (daData), DataSet (dsLookupData), and DataSet (dsData), all created via the IDE...
5
1055
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
2333
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 populating a listbox with an array of very simple "Country" objects via a WebService. The Country class contains CountryID,TLDs and Name properties each...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5512
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
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 we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.