Skip to content

How to set the value in the drop down list.

sita k

Asked Mar 10, 2013, 8:27 PM EDTSolved
Share
LinkedInX
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?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Vishal Gilbile
    ✓ Accepted answer0
    Hello,
          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.
    0
  • 1 short reply
    • 0
      Thanks Vishal.
      0