?
Solved

ASP DropDownList DataBind DataTextField = 'Lastname/Firstname'?

Posted on 2012-03-14
3
Medium Priority
?
520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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