 |
| 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
|
|
|
|

September 19th, 2007, 09:32 PM
|
|
Authorized User
|
|
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
2 table views in DropDownList control
Hi
I'm trying to link my DropDownList control to my database which contains 2 fields, "Name" and "Email". However, the DropDownList control can only display either name or email. I would like it to be combined to display the name on the left half of the DropDownList, and the email on the right half.
Can this be done?
Thank you
|
|

September 19th, 2007, 11:46 PM
|
|
Authorized User
|
|
Join Date: Apr 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I think up to today there is no any way to link two column with single dropdown list. and just tell why it is required so we other member can understand nad give a beeter solution to you. Ya if you don't mind then there one trick. Do it with datareader first take one field to string then take second field and make single string then add it into drop down list
like
whule(datareader.read()
{
string s = datareader["field1"].tostring() + datareader["field2"].tostring();
dropdownlistname.items.add(s);
}
I hope it will solved your problem.
TarDuk - A Memory Beyond The Life.
|
|

September 20th, 2007, 08:05 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
hi there...
a better way will be to do it when you do the query and then pass the table, reader or whatever to the datasource of the combo...
that way you avoid an iteration...
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
|
|

September 20th, 2007, 08:13 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
To illustrate what Gonzalo is saying, what ever query you are using to populate your datasource change it so it looks something like this:
SELECT
field1 + ' ' + field2 as DataTextField,
field3 as DataValueField
From table
hth
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
================================================== =========
|
|

September 21st, 2007, 01:11 AM
|
|
Authorized User
|
|
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
Thank you for all your replies.
I'll be trying the combined method although I'm trying to avoid because I still need to use them, which I have to substring it.
Thank you so much!
|
|

September 21st, 2007, 09:34 PM
|
|
Registered User
|
|
Join Date: Sep 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am totally new to ASP.Net but do a lot of windows VB.Net, so I will throw out my idea and see the reactions...
First of all I would use a global datatable and then the selected index of the drop down would be the row index into the datatable to retrieve the original data...
Or I would create an array for the values I want to recover and, again, the selected index from the drop down would be the array index to the actual value I need.
Is this possible in ASP.Net? Not sure since there could be many users at one time and would does ASP.Net keep a datatable or array for each?
If this is a stupid idea, I apologize, but it is how I learn.
John
|
|

September 21st, 2007, 10:04 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Hello John.
Normally, when I need to do something similar to the Original Posters question my SQL Table looks something like this:
PK TextField TextField
So, in the context of this example my query would be something like:
SELECT
PK,
TextField + ' ' + TextField
FROM Table
I would bind pk as the DataValue and the TextField colum as the DataText for the dropdown. This situaion is more akin to your idea about an array list, although I wouldnt create an arraylist and then bind that to the dropdownlist, i would just bind directly to my dataset from SQL.
I would not use a global datatable for this. I would probably bind to an instance of a datatable/set or a data reader to accomplish this.
Cheers.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
================================================== =========
|
|

September 23rd, 2007, 10:20 PM
|
|
Authorized User
|
|
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
Thank you so much for all of your replies!
Think I cannot escape this portion.
I understand how to combine them already, but I had been trying on how to separate them. Below are my codes:
Dim try as string = "Remy| [email protected]"
dim found as integer = try.indexof("|")
dim result as string = try.substring((found + 1),try.length)
The error returned to me was arguement our of range. How can I rectify this problem?
Thank you
|
|

September 24th, 2007, 02:18 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You actually don't need to separate them in code, you can do it (too) with SQL.
Just select the fields as you would normally do and then combine them:
SELECT PK, Name, Email, (Name || ' ' || Email) as Combined FROM MyTable (in PostgreSQL, not sure about the syntax SQL Server uses for string concatenation)
|
|

September 24th, 2007, 02:37 AM
|
|
Authorized User
|
|
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi! Thanks for replying, however, I don't really get what you mean from here, "(Name || ' ' || Email) as Combined FROM MyTable".
Sorry, I'm new to SQL statements.
Thank you!
|
|
 |