 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 7th, 2006, 04:00 AM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Multi column Dropdownlist control???
Hi programmers.
I have a table in my database that contains ID, Name and Family fields. I want to put values of name and family fields in a Dropdownlist in my ASP.NET Project. I set the Datavaluefield of Dropdownlist to "ID" but i don't know how to set the Datatextfield property of my Dropdownlist to show both Name and Family fields?
Please help me.
|
|

December 7th, 2006, 05:27 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
You can't do that directly in the control. The easiest way around this is this:
Add an additional column in your query that combines the two fields:
SELECT ID, Name, Family, Name + ' ' + Family AS FamilyName
This combines the two fields on the fly and gives you a new column called FamilyName that you can use in the drop down list.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

December 7th, 2006, 06:01 AM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you very much comrade. You offered a very good idea....
in my c# code i write:
dropdownlist.datatextfield="FamilyName";
dropdownlist.datavaluefield="ID";
is this true?
thanks again my friend.
Quote:
quote:Originally posted by Imar
Hi there,
You can't do that directly in the control. The easies way around this is this:
Add an additional column in your query that combines the two fields:
SELECT ID, Name, Family, Name + ' ' + Family AS FamilyName
This combines the two fields on the fly and gives you a new column called FamilyName that you can use in the drop down list.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|
|

December 7th, 2006, 06:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Why don't you try it out and see for yourself?
But yes, it's true. The new column is available the same way as you would access other columns, so you can set things like DataTextField and DataValueField.
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

December 29th, 2006, 01:01 PM
|
|
Registered User
|
|
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If you want a more columnar layout -- and not just concatenated fields -- there are some good third-party controls out there like http://easylistbox.com/demoColumns.aspx?rl=wp2p .
|
|

January 17th, 2007, 07:24 AM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Peter, but i prefer to do Imar's offer.
|
|

June 7th, 2007, 11:40 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Imar!
|
|
 |