Reputation: 31
I want to know how to attach a SelectListItem
to a SelectList
object :
I create an SelectListItem
as :
SelectListItem sl = new SelectListItem() { Text = "-99", Value = "Select a Value" };
Now I want to attach the item to below SelectList:
public SelectList lstCCPerfOrg { get; set; }
Please help.
Thanks,
Upvotes: 1
Views: 2853
Reputation: 721
var selectList = new SelectList(
new List<SelectListItem>
{
new SelectListItem {Text = "-99", Value = "Select a Value"}
}, "Value", "Text");
Upvotes: 1
Reputation: 3362
SelectList
Represents a list that lets users select one item.Hence the input should be list of items. The SelectList
has accept only IEnumarable
of Items.
List<SelectListItem> sl = new List<SelectListItem>()
{
new SelectListItem() { Text = "-99", Value = "Select a Value" }
};
SelectList lstCCPerfOrg = new SelectList(sl);
Upvotes: 1