Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have IPagedList to bind datatable and inside table there is a dropdownlist but i am unable to set dropdown selected value

Controller

C#
foreach (var item in model.OrderMethod)
{
    item.StatusList.Add(new SelectListItem() { Text = "Pending", Value = "0" });
    item.StatusList.Add(new SelectListItem() { Text = "Sent", Value = "1" });
}


View

@using MvcPaging
@model IPagedList<projectname.areas.admin.models.ordermodel>

C#
@foreach (var item in Model)
{
    if (item != null)
{
<tr><td>@Html.DropDownListFor(m=>m.FirstOrDefault().SelectedStatusId, item.StatusList)</td></tr>
}
}





I am providing the value of SelectedStatusId 0 or 1 but unable to set it's selected value.
Posted
Updated 3-Jun-15 23:44pm
v3

1 solution

C#
foreach (var item in model.OrderMethod)
{
    item.StatusList.Add(new SelectListItem() { Text = "Pending", Value = "0" });
    item.StatusList.Add(new SelectListItem() { Text = "Sent", Value = "1", Selected=True });
}
 
Share this answer
 
v3
Comments
itsathere 5-Jun-15 3:09am    
it's not exact solution..i have to do it dynamically or on database value
btw yesturday, i have solved it by myself.

Thanks.
Yogesh Kumar Tyagi 5-Jun-15 7:58am    
ok Good...:)

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