473,809 Members | 2,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q: multiple fields in dropdown list

Hello,
I am suing SELECT * from MyTable in a stored procedure and populate dropdown
list. By using followings:
ddlSP.DataSourc e = DS;
ddlSP.DataTextF ield = "PName";
ddlSP.DataValue Field = "PID";
ddlSP.DataBind( );

This show PName in dropdown list, It is working fine. Now I need to combine
PName, Field1 and Field2 as “PName: Field1 – Field2” and show it in the
dropdown list?
How should I do this?
Thanks,
Jim.
Nov 19 '05 #1
3 3162
I'm fairly new so my syntax might be off, but I have done something
similar. You need to combine the field names in your select statement
and then assign them to an alias which you will use in your
DataTextField value.

Here's a quick sample:

SELECT PName + ': ' + Field1 + ' - ' + Field2 AS MyAlias FROM MyTable
....
ddlSP.DataTextF ield = "MyAlias";

The + operator concatenates the strings (similar to & in VB).
The AS keyword assigns the results to a new field name in the
datareader (also useful when accessing multiple fields with the same
name in one query).
Depending on the datatypes in the table, you may see some errors about
type conversions. You may need to convert one or more of the field
types using convert... something like this for converting to varchar:

convert(varchar (4),Field1)
(which converts the contents of Field1 into a varchar, length 4)

Nov 19 '05 #2
You can also do this manually for each item in the datasource.
For a Datareader

While dr.Read()

dropDownList1.I tems.Add(New ListItem(dr("fi eld1"), dr("field2")))

End While

The Add method takes in a String or a ListItem object.

--
TDAVISJR
aka - Tampa.NET Koder
"Elroyskimm s" <el*********@ya hoo.com> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.com.. .
I'm fairly new so my syntax might be off, but I have done something
similar. You need to combine the field names in your select statement
and then assign them to an alias which you will use in your
DataTextField value.

Here's a quick sample:

SELECT PName + ': ' + Field1 + ' - ' + Field2 AS MyAlias FROM MyTable
...
ddlSP.DataTextF ield = "MyAlias";

The + operator concatenates the strings (similar to & in VB).
The AS keyword assigns the results to a new field name in the
datareader (also useful when accessing multiple fields with the same
name in one query).
Depending on the datatypes in the table, you may see some errors about
type conversions. You may need to convert one or more of the field
types using convert... something like this for converting to varchar:

convert(varchar (4),Field1)
(which converts the contents of Field1 into a varchar, length 4)

Nov 19 '05 #3
Ooops..got my synthax incorrect. However, this is answered in a previous
post. See
Subject: Adding List Item Value
Date: 4/12

The correct synthax is shown there

--
TDAVISJR
aka - Tampa.NET Koder
"Elroyskimm s" <el*********@ya hoo.com> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.com.. .
I'm fairly new so my syntax might be off, but I have done something
similar. You need to combine the field names in your select statement
and then assign them to an alias which you will use in your
DataTextField value.

Here's a quick sample:

SELECT PName + ': ' + Field1 + ' - ' + Field2 AS MyAlias FROM MyTable
...
ddlSP.DataTextF ield = "MyAlias";

The + operator concatenates the strings (similar to & in VB).
The AS keyword assigns the results to a new field name in the
datareader (also useful when accessing multiple fields with the same
name in one query).
Depending on the datatypes in the table, you may see some errors about
type conversions. You may need to convert one or more of the field
types using convert... something like this for converting to varchar:

convert(varchar (4),Field1)
(which converts the contents of Field1 into a varchar, length 4)

Nov 19 '05 #4

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

Similar topics

2
9626
by: Jas | last post by:
I want an ASP page with a dropdown and a simple button. Every time the user chooses an item from the dropdown and clicks on the button i want that value written below in list and allow user to select more. Also how can these choices be saved somehow so tha when the user goes to the next page the choices he made can be written to the database. For example The choices in the dropdown may be
2
1361
by: Smythe32 | last post by:
Hi, I have this code below that will add a new item to a combo box if it is not in the combo box. I also would like the user to add the description for the new addition to the combo box and select a category that it falls into. The description field is a 255 text field. The category will need to be selected from a dropdown list and then added to the main reason table. tblReasonCodes has the following fields, all 255 text.
0
2235
by: rayone | last post by:
Hi folks. I need advice. 2 options, which do you think is the better option to display/retrieve/report on the data. Keep in mind reporting (Crystal), SQL Performance, VB Code, usability, architecture. Case 1: On a web page I would like to render a dropdown list
2
1333
by: Harry | last post by:
Hi, Quick question regarding dropdownlists. On one page I have 10 asp:dropdownlists. The user selects an option from a dropdown list and then it updates an asp:label with the relevant text. The user must select an option from each dropdown list. All the dropdownlists are to be populated from a SQL database.
4
6106
by: jayscott1 | last post by:
What I would like to do is have the user start typing in the last name and as they were typing it would retrieve names from the database and give a drop down like autosuggest in google. That much I have figured out. But what I really want is once the name is in the field I would like it to retrieve the rest of the information from the database ie. firstname address etc. and put it other fields on the form. Is this possible?
1
2116
by: jjuan | last post by:
I have a multiple dropdown which have multiple selection. If I select multiple value on my multiple dropdown list and submit it,how can i write it on the tblotherlang sample code <select size="10" name="ddmultiplelang" multiple> <%
1
6809
by: tech.fors | last post by:
Hi , How to make multiple select in dropdown list box using asp and access can anyone help me regarding this. thanking u in advance, Regards, tech.fors
8
2935
by: Wingot | last post by:
Hey, I have a program I am trying to write using Visual C#, SQL Server 2005/2008, and Visual Studio 2008, and one part of it includes a Schema called Client. Inside this schema, three tables exist named Country, MedicalCondition, and Customer.
2
1821
by: permander kumar | last post by:
hi plz help me, i have a code in which two multiple selection dropdown list. in first list if I am select single value the data are fetch in second table on button click. but the problem is in first dropdown list the second field is also select after the page submit. the code is <?php include("connect.php"); ?> <html><body>
0
9721
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9603
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10640
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10387
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7662
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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

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.