0

i can view anybody record and then can edit it if i click edit button below record, after clicking it takes you to another page whihc shows textboxes and dropdown, checkboxes to edit and all textboxes contains values for that EmpID but problem is that i want pre selected value in DROPDOWN LIST, like it should pick corresponding value for each user a preselected like my textboxes. I am using LINQ TO SQL, MVC 3, asp.net C#

Controller:

var DepNames = (from n in DataContext.HrDepts select new { n.DeptID, n.DeptName }).Distinct();
               ViewData["DeptName"] = new SelectList(DepNames, "DeptID", "DeptName", EmployeeValues.FirstOrDefault().DeptName);

View:

@using EmployeeAttendance_app.Models
@model IEnumerable<GetEmployeeEditDetails_SpResult>

@{
    var Item = Model.FirstOrDefault();
 }
@Html.DropDownList("DeptID", (SelectList)ViewData["DeptName"])
3
Contributors
3
Replies
17
Views
3 Years
Discussion Span
Last Post by cxzei
0

It is better to use the "dropdownlist.selected" attribute in the backend at page_Load event to the particular value which you want it to be selected.

0

do something like...

DropdownList1.SelectedIndex = DropdownList1.Items.IndexOf(DropdownList1.Items.FindByText(someTextvalue))

0

do something like...

DropdownList1.SelectedIndex =    
   DropdownList1.Items.IndexOf(DropdownList1.Items.FindByValue(somevalue))
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.