dropdownlist text field format

hey guys, i have a dropdownlistbox and i am pulling information from a database,

i want to display information like this in the list

name(surname)

here is my c# code which display only the name and the ID number has a value

        ddIndentityNumber.Items.Clear();
        ddIndentityNumber.Items.Add("List of drivers names:");
        ddIndentityNumber.DataSource = D.Return_driver();
        ddIndentityNumber.DataTextField = "name";
        ddIndentityNumber.DataValueField = "indentity_number";
        ddIndentityNumber.DataBind();

please some one show me how to join the name with the surname?
JCWEBHOSTAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
you have to change it in datasource, DataTable or Object List
if you are using Data Table then use computational Column and if you are using objects the add a new property wich concatinate the other two.
0
JCWEBHOSTAuthor Commented:
yes, i am using datatable, can you please show me how to concatinate? in C# code?
0
Pratima PharandeCommented:
you are getting data from databas
ethen change the query like this

Select name + '(' + surname + ')' as name from tablename

so that you will get data in name column itself no need to change .netcode
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

JCWEBHOSTAuthor Commented:
i do not want to mess around with the query.
0
Pratima PharandeCommented:


 you want to show two data in a dropdownlist, you can combine two columns into 1 column and assign to the DataTextField
see the example

daAdapter = new SqlDataAdapter("SELECT course_type, course_num FROM tbl_course_offerings WHERE..........",con);
daAdapter.Fill(dsCourse,"Course");
 
dcolFullCourse.ColumnName = "FullCourse";
dcolFullCourse.DataType = System.Type.GetType("System.String");
dcolFullCourse.Expression = "course_type + ' ' + course_num";
 
dsCourse.Tables["Course"].Columns.Add(dcolFullCourse);
 
ddlCourse.DataSource - dsCourse.Tables["Course"].DefaultView;
ddlCourse.DataTextField = "FullCourse";
ddlCourse.DataValueField = "course_num";
0
JCWEBHOSTAuthor Commented:
can i use textformatstring?
0
Pratima PharandeCommented:
0
Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
Hi,
You can use following as:

DataTable dt = D.Return_driver();
dt.Columns.Add("Newname", System.Type.GetType("System.String"), "FirstName+'('+SirName+')'");
ddIndentityNumber.DataSource = dt;

Thanks
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JCWEBHOSTAuthor Commented:
Works great!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.