Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi There,

I need to display data in table ,and one column should be a drop-down selection for updation. Drop-down need to be populate with already selected value in DB.

Please check my code, and suggest a way to set selected value

What I have tried:

C#
<pre lang="c#">
<table class="table table-striped">
    <tr>
        <th>Title</th>
        <th>Status</th>
        <th>User Name</th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.title)
            </td>
            <td>
                @if (item.status == (short)Online_Book.Models.BookStatus.Available)
                {
                    <span>Available</span>
                }
                else
                {
                    @Html.DropDownListFor(m => item.status, new SelectList(Online_Book.Models.BookStatus.GetValues(typeof(Online_Book.Models.BookStatus)), item.status), new { @class = "form-control" })


                }
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.username)
            </td>
        </tr>
    }

</table>
Posted
Comments
Richard Deeming 22-May-20 15:58pm    
If item.status is set correctly, then your list should work. What's the problem?
Kasthuri Gunabalasingam 22-May-20 16:45pm    
yea It's checked correctly.but drop down not showing the set value

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