Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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
 
Old August 10th, 2009, 08:22 AM
Registered User
 
Join Date: Aug 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Concatenation in DropDownList

Expanding on this great textbook, I'm wanting to concatenate two data fields into a dropdownlist box.

In ASP Classic, I would just take the two fields (e.g, rst(0) and rst(1)) and concatenate them with an "&". For example, "LastName, FirstName" would be like this: rst(0) & ", " & rst(1) with a hidden Id number to requery the database.

Can this be done in an <asp:DropDownList DataTextField="LName"> ? Or, does this have to be done in CodeBehind? I'm looking for something like:
<asp:... DataTextField = "LName & FName">

Thanks.

Patrick W
Texas
 
Old August 10th, 2009, 09:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Patrick,

Glad to hear your like the book.

You can't do this in markup, but you could do it in Code Behind. However, this requires quite a bit of code, so it's probably easier to do this in SQL:

SELECT FirstName, LastName, FirstName + " " + LastName AS FullName

And then use FullName to bind the DDL. You may need some NULL checking to avoid empty items, but other than that, this should do the trick.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 10th, 2009, 10:30 AM
Registered User
 
Join Date: Aug 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update on Concatenation

Imar,

Yes, your book is excellent--meticulously researched and written.

Your solution worked great. Now, I need to populate a grid with the user selection from DropDownList (i.e., another trip to the database). I think the answer is in Chapter 13, and I'm getting ready to review it one more time.

I'll be back in contact with you if I'm unsuccessful...

Thanks again for your speedy response!

Patrick





Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatenation question, please savoym VBScript 12 May 5th, 2009 02:30 PM
Aggregate Concatenation 12th_Man SQL Language 4 January 10th, 2006 03:26 PM
Concatenation of fields JpJoe Access 8 April 8th, 2005 01:32 AM
string concatenation nulogix PHP How-To 1 June 24th, 2004 06:17 AM
string concatenation matt_99 Access VBA 2 January 17th, 2004 09:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.