Hi,
I have 2 tables Employee and Works_On.While assigning work to employee i selected employee name in the drop down list.While storing those details in the works_on table i should store emp_id in the place of employee name.
In c# for drop down list i used sqldatasource and selected emp_name field from employee table.How to return emp_id.Do i need to implement it in the coding or in the properties?
How to set the value in the drop down list.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Vishal GilbileRank #269 · 9.4K pointsPosted Mar 10, 2013, 8:49 PM EDT
While binding the employee table data to dropdownlist you need to set the following properties.
dropdownlist1.DataMember=dropdownlist1.DataValueField="EmpId";
dropdownlist1.DataTextField="EmpName";
And whenever you are retrieving the value.
string id=dropdownlist1.SelectedValue.
Hope that solves your problem.
With Regards,
Vishal Gilbile.
1 short reply
sita k29 pointsPosted Mar 11, 2013, 8:36 PM EDT