Click here to Skip to main content
13,048,584 members (91,908 online)
Rate this:
Please Sign up or sign in to vote.
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 10-Oct-12 2:44am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

or Create SelectList and mention your selectedValue in Action
SelectList Banks = new SelectList(new Department().Seed(), "DepartmentName", "DepartmentId", "SelectedValue");
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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, 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100