473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataBinding and drop-down lists

There is no dearth of this subject in this group, but I am not sure if
it answers this question. If this question is stupid, please let me
know it is and excuse my ignorance.

SQL Query: select user_id,first_name,last_name from user

I have a drop-down list that needs to fill in the name of the user in
the format "FirstName LastName" using standard databinding techniques.
This is the code that I have

A dataReader contains the resultset.

cboUser.DataSource = dataReader
cboUser.DataValueField = "user_id"

I do not know how to get the "FirstName LastName" in the dropdown list.
I tried something like

cboUser.DataTextField = String.Concat("first_name"," ","last_name")

and it is of no avail.

An error is thrown on the call to DataBind() and the message says that
"first_name last_name" is not comprehensible.

I am not at liberty to change the sql query to do the concatenation.
Is there a way out?

Thanks,
-Sankar

Nov 19 '05 #1
2 970
I am not at liberty to change the sql query to do the concatenation.
Is there a way out?


Well.... if you have the option of getting kinda dirty and use a dataAdapter
and a dataset to fill your dropdownlist, this could work:
ds.tables("Customers").Columns.Add("OurNewCombined Column",
GetType(System.String), "[CompanyName] + ', ' + [ContactName]"
DropDownList1.DataSource = ds
DropDownList1.DataTextField = "NewColumn"
DropDownList1.DataBind()

Hope it helps.

Jeppe Jespersen
Nov 19 '05 #2
Hi Jeppe,

Thanks for the information. I could accomplish what I needed with your
idea.

It is hard for me to believe that it is convoluted though :-)
Thanks again. I appreciate it.

-Sankar

Nov 19 '05 #3

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

Similar topics

15
by: Tim Jarvis | last post by:
Hi, I have an object that I am binding to a text box, this object exposes a boolean field, and I have implemented a format event handler and a parse event handler for the binding object, where I...
2
by: Johann Blake | last post by:
I've been playing around trying to bind textbox controls and datagrids to typed datasets. Up until recently, I never used DataBindings. I always manually wrote the value into a textbox and stored...
0
by: vbMental | last post by:
I created a user control that, had a datalist with checkboxes inside of the item template. These checkboxes would not retain state. For instance, if I set them to checked inside of the load event...
3
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method,...
0
by: Simon Gregory | last post by:
I am currently attempting to figure out how the new databinding stucture works in ASP.NET 2.0 after working with v1.0 & v1.1 for several years. It seems that if you wish to do set up databinding...
0
by: Anthony Malt | last post by:
Hallo, kann jemand ein Win Form-Control empfehlen, das Databinding unterstützt und auch Drag & Drop? Danke für jeden Tipp und Gruß Anthony Malt
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
8
by: Dirk | last post by:
Hello, I have a problem to use databinding with my business layer classes. My data class does not have simple properties (string, int or datetime), instead, all my properties are objects of the...
3
by: moondaddy | last post by:
I have a windows WPF sample project which is starting to work pretty good. I can drag shapes and lines, and connect a straight line to any place on a custom rectangle shape's boarder. Now I have a...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello to all, I want to know if DataBinding in asp.net 2,0 is better than to fill up the values of the controls of the following form: this.miControlTextBox.Text = valorParaControlTextbox; ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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
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,...
0
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...
0
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
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...
0
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,...

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.