Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Suppose I have the following two tables in SQL Server database:

Table_Order
- idOrder (int)
- OrderNumber (int)
- fk_Customer (int)

Table_Customer
- idCustomer (int)
- CustomerName (nchar)

There is a foreign key fk_Customer in Table_Order that points to the primary key idCustomer in Table_Customer, so that I can pull associated CustomerName for an order.

So, I have a DropDownList that shows Orders with following attributes bound to it:
- Data Value Field: idOrder
- Data Text Field: OrderNumber

In the DropDownList, is it possible to also show the associated CustomerName along with the OrderNumber, for example:
C#
DDL.DataTextField = OrderNumber + " (" + CustomerName + ");
Posted

Hello friend, to achieve that you have to create a field concatenating two columns as per your need at the SQL level as follows:
SQL
SELECT O.idOrder, O.OrderNumber + '(' + C.CustomerName + ')' AS Order_Customer
FROM TableCustomer C INNER JOIN TableOrder O ON C.idCustomer = O.fk_Customer
Then you can set DataTextField as shown below:
C#
DDL.DataTextField = "Order_Customer"

- DD
 
Share this answer
 
Comments
Member 8179886 14-Jun-14 7:45am    
Thank you, this was exactly what I looked for :)
Debabrata_Das 14-Jun-14 7:51am    
WC :)
first the select query:
select idorder, convert(varchar, ordernumber) + " (" + customername + ")" as orderno from order join customer on fk_customer = idcustomer

then the ddl:
Data Text Field: orderno
 
Share this answer
 
Comments
Nirav Prabtani 14-Jun-14 7:41am    
my 5+
Peter Leow 14-Jun-14 8:27am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900