Solved

ASP DropDownList DataBind DataTextField = 'Lastname/Firstname'?

Posted on 2012-03-14
3
502 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
error on the asp.net page 1 33
Name space syntax error 12 39
Interview questions for support of a legacy ASP.NET site 4 37
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

22 Experts available now in Live!

Get 1:1 Help Now