|
asp .net mvc populate a dropdownlist from DataSet
// Controller CODE.
List list = new List { };
foreach(DataRow oDataRow in oCountry.DataSetCountry.Tables[0].Rows)
{
SelectListItem oSelectListItem = new SelectListItem { Value = (String)oDataRow["CountryCode"],Text = (String)oDataRow["CountryName"]};
list.Add(oSelectListItem);
}
ViewData["DDLCountry"] = list;
// View Code
<%= Html.DropDownList("DDLCountry")%>
|