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
Solved

ASP DropDownList DataBind DataTextField = 'Lastname/Firstname'?

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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