Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get the selected drown drop value from database..i'm storing employee details in one table with drop down selected value(integer) and in other table drop down value and text.
my models

C#
public class EmployeeDetails
    {
        public int empid {set;get;}
        public string empname{set;get;}
        public string empdesig{set;get;}
        public decimal empsal{set;get;}
        public int education{set;get;}
        public DateTime time{set;get;}
        public string dropdownname { set; get; }
    }
public class DropDownList
{
    public int dropdownId { set; get; }
    public string dropdownName { set; get; }

}` public class DisplayEmployeeViewModel
{
    public IEnumerable<EmployeeDetails> EmployeeDetails { set; get; }

    public DisplayCreateEmployeeViewModel createemployee { set; get; }

    public string TabName { set; get; }
    public List<SelectListItem> DropdownSelectListItems
    {
        get
        {
            var dropdown = (new DropdownRepository()).GetDropdownTypes();
            var entityList = dropdown.Select(x => new SelectListItem()
            {
                Text = x.dropdownName,
                Value = x.dropdownId.ToString()
            });
            return entityList.ToList();
        }

    }

} public class DisplayCreateEmployeeViewModel
{
    public EmployeeDetails EmployeeDetails { set; get; }
    public int empid { set; get; }
    public string empname { set; get; }
    public string empdesig { set; get; }
    public decimal empsal { set; get; }
    public int education { set; get; }
    public DateTime time { set; get; }
    public string dropdownname { set; get; }

    public List<SelectListItem> DropdownSelectListItems
    {
        get
        {
            var dropdown = (new DropdownRepository()).GetDropdownTypes();
            var entityList = dropdown.Select(x => new SelectListItem()
            {
                Text = x.dropdownName,
                Value = x.dropdownId.ToString()
            });
            return entityList.ToList();
        }

    }
}` <div>
                <table id="tblemployeedetails" class="table table-hover table-bordered table-responsive "  >
                       <thead style="background-color:black;color:white; ">
                           <tr>
                               <th></th>
                               <th>Employee Name</th>
                               <th>Employee Designation</th>
                               <th>Enployee Education</th>
                               <th>Employee Salary</th>

                           </tr>
                       </thead>
                <tbody>
                        @foreach (EmployeeDetails details in Model.EmployeeDetails)
                        {
                            <tr>
                                <td>@Html.CheckBox("status" + details.empid, new {value=details.empid,@class="detailCheckBox" })</td>
                                <td>@Html.TextBox(details.empname, details.empname, new {@class="txtdisable" })</td>
                                <td>@Html.TextBox(details.empdesig, details.empdesig, new { @class = "txtdisable" })</td>
                                <td>@Html.DropDownList(details.education.ToString(),Model.DropdownSelectListItems, new { @class = "txtdisable" })</td>
                                <td>@Html.TextBox(details.empsal.ToString(), details.empsal, new { @class = "txtdisable" })</td>


                            </tr>
                        }
                </tbody>

                   </table>


            </div>

C#
the code which i'm showing fetching the drop down complete list and showing. here i'm getting the list of drop down.But i want to get the list with selected text( stored value should select)

how to do that


What I have tried:

i'm getting the whole drop down list but not getting the selected text with was stored in the database. how to get the text as selected
Posted

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