JCWEBHOST
asked on
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.Cl ear();
ddIndentityNumber.Items.Ad d("List of drivers names:");
ddIndentityNumber.DataSour ce = D.Return_driver();
ddIndentityNumber.DataText Field = "name";
ddIndentityNumber.DataValu eField = "indentity_number";
ddIndentityNumber.DataBind ();
please some one show me how to join the name with the surname?
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.Cl
ddIndentityNumber.Items.Ad
ddIndentityNumber.DataSour
ddIndentityNumber.DataText
ddIndentityNumber.DataValu
ddIndentityNumber.DataBind
please some one show me how to join the name with the surname?
ASKER
yes, i am using datatable, can you please show me how to concatinate? in C# code?
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
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
ASKER
i do not want to mess around with the query.
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,"C
dcolFullCourse.ColumnName = "FullCourse";
dcolFullCourse.DataType = System.Type.GetType("Syste
dcolFullCourse.Expression = "course_type + ' ' + course_num";
dsCourse.Tables["Course"].
ddlCourse.DataSource - dsCourse.Tables["Course"].
ddlCourse.DataTextField = "FullCourse";
ddlCourse.DataValueField = "course_num";
ASKER
can i use textformatstring?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Works great!!!
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.