Click here to Skip to main content
14,549,600 members
Rate this:
Please Sign up or sign in to vote.
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:

<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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100