How to show two values(columns) in dropdownlist

Feb 28 2014 2:06 AM
I have a asp:dropdownlist I'm binding two values(columns from sql table) to it 1.EmpId and 2.EmpName 1 as DataText field and 2 as DataValueField its fine  but my requirement is i want display both 1 and 2 in the dropdownlist

E-001    shashi
E-002    Abhijit
E-003    Laxmanan

when select EmpId should be selecteditem and EmpName should Selectedvalue

i have written the my code like this but i am getting problem with selecteditem due to concating..

 public void BindEmp()
        Ds = ObjTrip.BlOnLoadTrip();
        DataTable Dt = new DataTable();
        string Eid = string.Empty;
        string EmpName = string.Empty;
        string EIdEname = string.Empty;

        Dt = Ds.Tables[2];
        foreach (DataRow dtr in Dt.Rows)
            Eid = dtr["EmpCode"].ToString();
            EmpName = dtr["Driver"].ToString();
            EIdEname = Eid + "------------" + EmpName;
            ddlDriverName.Items.Add(new ListItem(EIdEname, Eid));


selecteditem: E-002------------Abhijit



Answers (6)