获得选定的价值 [英] getting selected value

查看:105
本文介绍了获得选定的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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:
 
Controller:
 
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);
            }
VIEW:
 
@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", "Select Shift")
  <br />
  <label id="lblEntryDate" class="TxtBoxFrom editEmp_label">Entry Date</label>
  <input type="text" value= @Item.EntryDate class="TxtBoxTo" name="EntryDate" placeholder="Update Date"  />
  <br />
  <label id="lblSalary" class="editEmp_label">Salary</label>
  <input type="text" value= @Item.BasicSalary  name="Salary" placeholder="Update Salary"   />
  <br />
  <label id="lblEmail" class="editEmp_label">Email</label>
  <input type="text" value= @Item.EmailAdd  name="Email" placeholder="Update Email"   />
  <br />
  <br />
  <button type="submit" id="btnUpdate" class="button_AdminPanel" style="width:75px" name="btnSubmit">Update</button>  
  
}

推荐答案

你必须在页面加载中绑定下拉列表
you have to bind the dropdownlists in page load


@Html.CheckBox("Approval", @Convert.ToBoolean( @Item.OvertimeApproved))


这篇关于获得选定的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆