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?
 
Imran Javed ZiaConnect With a Mentor Consultant 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
 
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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
 
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
 
JCWEBHOSTAuthor Commented:
Works great!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.