Hi frnds,
am working on asp.net c# SqlServer.
I want to Concatenate two columns(DeptUserName,Dept_Code) from sqlServer Table and display in dropdownlist.
In dropdownlist it should appear as
------Select---------
Sandeep - IT
Ranjith - Finance
Sukumar - Logistics
here Sandeep is DeptUserName and IT is Dept_Code.
So how to Concatenate...
This is my code.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillDepartments();
}
}
private void FillDepartments()
{
//con.Open();
SqlCommand cmdFill = new SqlCommand("SELECT [DeptUserName] + ' ' + ' ' + [Dept_code] as Creator from Depts Order By Dept_code", con);
SqlDataAdapter daFill = new SqlDataAdapter(cmdFill);
DataSet ds = new DataSet();
daFill.Fill(ds);
ddlDepartment.DataSource = ds;
ddlDepartment.DataTextField = "DeptUserName";
ddlDepartment.DataValueField = Dept_code
ddlDepartment.DataBind();
ddlDepartment.Items.Insert(0, new ListItem("---- Select Department ----", "0"));
//con.Close();
}
Please your help is Required.
Thanks.