.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 19th, 2004, 04:27 PM
Grendal_p Grendal_p is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 Grendal_p User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Databinding datatextfield in a Drop Down List

I am attempting to bind data to a dropdownlist. Currently the below code will bind a persons last name just find using the datatextfield. What I would like to do though, is also be able to bind there First Name as well into that datatextfield, so that when the drop down list is displayed, they see a Last Name, First Name, rather than just a persons last name.

cmdname =
New SqlClient.SqlCommand("SELECT id, lname, fname from app_personal", conn)
dtrname = cmdname.ExecuteReader()
ddlname.DataSource = dtrname
ddlname.DataTextField = "lname"
ddlname.DataValueField = "id"

ddlname.DataBind()
dtrname.Close()

Any help would be much appreciated...

Thanks in advance...

Reply With Quote
  #2  
Old February 20th, 2004, 01:27 PM
StudioReview StudioReview is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 30 StudioReview User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
There's a lot of ways to do this but given the code you provided, the easiest way is to leverage SQL to do what you want. Check this out:

cmdname = New SqlClient.SqlCommand("SELECT id, lname, fname, rtrim(fname) + ' ' + rtrim(lname) as fullname from app_personal", conn)

then bind the fullname column:

ddlname.DataTextField = "fullname"

I hope this helps!
__________________
Tivo Codes, Hacking the Tivo, and Adding a Second Drive to Your Tivo.
All this information at www.TivoSpy.com !

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Databinding datatextfield in a Drop Down List


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap