Solved

ASP DropDownList DataBind DataTextField = 'Lastname/Firstname'?

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

697 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