Click here to Skip to main content
14,869,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have emp table and empno,name,deptno(fk from department table)column.when i insert new employee i give name and department no in drop down list. i can display department name in dropdown list and i can store department no in emp table.but my problem is when i try to edit the particular employee then i can't bind that particular department no,name in drop down list.

in [httpget]
i get id, name (no problem)and my drop down department list should be return save department no,name and then if i want then i can change department(now i load that list but it selected the first value and if i don't change department then it update department first value as it is already selected)
Posted

If you are using Razor Views
Use optionlabel in View
C#
@Html.DropDownListFor(model => model.FieldName, (SelectList)ViewBag.DepartMent, Model.FieldName)

or Create SelectList and mention your selectedValue in Action
C#
SelectList Banks = new SelectList(new Department().Seed(), "DepartmentName", "DepartmentId", "SelectedValue");
   
v2
Thank your suggestion. actually i did mistake. when i create helper class i give name dept but when i call this i call deptid instead of dept.so, i correct it and it works.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900