var id = Session["staff_id"].ToString()
//I have datatable with 5 columns
DataTable dt = function_return_Datatable(id);
dropdownlist1.DataSource = dt;
/*in DataTextField I want to merge two columns of DataTable, dt.columns [1] is First Name and dt.columns [2] is LastName*/
//I tried this way to merge them, but no results
dropdownlist1.DataTextField = dt.Columns[1].ToString()+" "+dt.Columns[2].ToString();
dropdownlist1.DataValueField = dt.Columns[0].ToString();
dropdownlist1.DataBind();
Any ideas for how to merge these two columns?
You'll need a full name column in your data table as DataTextField can refer to only one single field:
DataTable dt = function_return_Datatable(id);
dt.Columns.Add("FullName", typeof(string), "FirstName + ' ' + LastName");
dropdownlist1.DataSource = dt;
dropdownlist1.DataTextField = "FullName";
dropdownlist1.DataValueField = "ID";
dropdownlist1.DataBind();
Should do it
(you could also add this column in your SQL query)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With