A way in which you could solve it is to create a List.
Say your Pay status is something like this:
public class PayStatus
{
int id;
string StatusName;
}
so you would do something like this:
IEnumerable<PayStatus> memberInvoiceStatus = new List<PayStatus>(dr.GetPayStatus());
var statusList = new List<SelectListItem>();
foreach(var status in memberInvoiceStatus)
{
statusList .Add( new SelectListItem()
{
Text = status.StatusName,
Value = status.id
Selected = status.StatusName == "MyDefaultStatus" // or some logic that will mark as True the item that you want to be the default selected one.
}
}
I guess you could still use it like you are using it, but instead of pasing this:
ViewData["memberInvoiceStatus"] = new SelectList(memberInvoiceStatus, "payStatusId", "payStatusText");
you would pass:
ViewData["memberInvoiceStatus"] = new SelectList(statusList , "payStatusId", "payStatusText");
although I think it is easier if you just added the list of SelectListItem
to the viewdata
ViewData["ListOfStatus"] = statusList;
and in the view you do something like this:
<%= Html.DropDownList("Status",ViewData["ListOfStatus"]) %>
that will make a list with the element that you marked as selected ( Selected = true
), as the default (selected) item.