Solved

ASP DropDownList DataBind DataTextField = 'Lastname/Firstname'?

Posted on 2012-03-14
3
491 Views
Last Modified: 2012-03-15
I successfully bind sql data to a dropdownlist like this:

string sql = "select id, lastname, firstname from clients";

 OracleConnection cn = DataAccess.OpenConnection();
 OracleCommand cmd = new OracleCommand(sql, cn);
 OracleDataAdapter da = new OracleDataAdapter(cmd);
 DataTable dt = new DataTable();        
 cn.Open();
 da.Fill(dt);
 DataAccess.CloseConnection(cn);

 ddl1.DataSource = dt;
 ddl1.DataTextField = dt.Columns["lastname"].ToString();
 ddl1.DataValueField = dt.Columns["id"].ToString();
 ddl1.DataBind();

Now I would like to make the ddl1.DataTextField = dt.Columns["lastname"].ToString() + "/" + dt.Columns["firstname"].ToString();

Help!
0
Comment
Question by:pointeman
  • 2
3 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 37720522
string sql = "select id, lastname + '/' + firstname as fullname from clients";

 OracleConnection cn = DataAccess.OpenConnection();
 OracleCommand cmd = new OracleCommand(sql, cn);
 OracleDataAdapter da = new OracleDataAdapter(cmd);
 DataTable dt = new DataTable();         
 cn.Open();
 da.Fill(dt);
 DataAccess.CloseConnection(cn);

 ddl1.DataSource = dt;
 ddl1.DataTextField = dt.Columns["fullname"].ToString();
 ddl1.DataValueField = dt.Columns["id"].ToString();
 ddl1.DataBind();

Open in new window

0
 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
ID: 37720544
sorry, forgot Oracle uses || instead of +:

string sql = "select id, lastname || '/' || firstname as fullname from clients";

 OracleConnection cn = DataAccess.OpenConnection();
 OracleCommand cmd = new OracleCommand(sql, cn);
 OracleDataAdapter da = new OracleDataAdapter(cmd);
 DataTable dt = new DataTable();         
 cn.Open();
 da.Fill(dt);
 DataAccess.CloseConnection(cn);

 ddl1.DataSource = dt;
 ddl1.DataTextField = dt.Columns["fullname"].ToString();
 ddl1.DataValueField = dt.Columns["id"].ToString();
 ddl1.DataBind();

Open in new window

0
 

Author Closing Comment

by:pointeman
ID: 37724300
thx
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now