Tuesday, May 22, 2018

Binding/Selecting Dynamic DropdownList

 var lstEMployeeName = EmployeeBL.GetEmployeeName();
 ViewBag.EmpDropDown = lstEMployeeName .AsEnumerable().Select(c => new SelectListItem { Text = c.Name.ToString(), Value = c.Id.ToString() }).OrderBy(i => i.Text);

 @for (int item = 0; item < Model.EmployeeItemList[item].Count; item++)
{ 
 @Html.DropDownListFor(m => m.EmployeeItemList[item].EmpID, new SelectList(ViewBag.EmpDropDown, "Value", "Text", @Model.EmployeeItemList[item].EmpID), "Select Employee Name", new { @class = "ddl-search panel-data  chzn-select-deselect", @style = "width:100%;" })
}
 public static List<ForDisplay> GetEmployeeName()
        {


            using (var entity = new EmpDataEntities())
            {
                var res = (from comm in entity.tbl_EMployee

                           select new ForDisplay
                           {
                               Id = comm.Id,
                               Name = comm.Name
                           }).ToList();
                return res;
            }
        }


 public class ForDisplay
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public ForDisplay()
        {

        }
        public ForDisplay(int pId, string pName)
        {
            Id = pId;
            Name = pName;
        } 
    }

No comments:

Post a Comment

javascript Filter/index off

 var family = [{"name":"Jack",  "age": 26},               {"name":"Jill",  "age"...