Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
4.20/5 (2 votes)
See more: , +
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#

CODE:

C#
@using EmployeeAttendance_app.Models
@model IEnumerable<GetEmployeeEditDetails_SpResult>
          
@{
    var Item = Model.FirstOrDefault();
 }
           
<style type="text/css">

</style>
<div>
@using (Html.BeginForm("EditEmployee", "Home", FormMethod.Get))
{
  <label id="lblName" class="editEmp_label">Name</label>
  <input type="text" value= @Item.EmplName  name="EmpName" placeholder="Update Name" />
  <br />
  <label id="lblDept" class="editEmp_label">Department</label>
  @Html.DropDownList("DeptID", @Item.DeptName)
  <br />
  <label id="lblShift" class="editEmp_label">Shift</label>
  @Html.DropDownList("ShiftId")


Controller:
C#
public ActionResult EditEmployee() 
        {
            if (!String.IsNullOrEmpty(Session["Admin"] as string))
            {
                int? EmplId = Convert.ToInt32(Session["EmpEdit"]);
                IEnumerable<GetEmployeeEditDetails_SpResult> EmployeeValues = DataContext.GetEmployeeEditDetails_Sp(EmplId).ToList();
                var DepNames = (from n in DataContext.HrDepts select new { n.DeptID, n.DeptName }).Distinct();
                ViewData["DeptID"] = new SelectList(DepNames, "DeptID", "DeptName");
                var ShiftNames = (from n in DataContext.AtdShifts select new { n.ShiftId, n.ShiftName }).Distinct();
                ViewData["ShiftId"] = new SelectList(ShiftNames, "ShiftId", "ShiftName");
                return View(EmployeeValues);
            }
Posted
Comments
Member 10517120 26-Feb-14 7:12am    
where u display ur data?
in a gridview ?

where exactly ur data resides?

if it comes from db then store it a viewstate and then cast it it to datatable again

use rowfilter using primary key
ZurdoDev 26-Feb-14 7:54am    
Where are you stuck then?
Joseph M. Morgan 26-Feb-14 11:26am    
Is it the Markup for creating a databound dropdown list that you are asking about, or how to bind the items in the list to a specific data source?
Hunain Hafeez 26-Feb-14 11:53am    
i am using MVC 3, RAZOR, asp.net C#, linq to sql

1 solution

This post might help you.
Aspirin for Select List Headaches
Joey
 
Share this answer
 

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