一、@Html.DropDownList
一、Html.DropDownList 通过linq 将datatable转换下拉列表
//查询城市 string CityId = WebCommon.Public.GetAdminCityId(); var CityList = WebBLL.Tbl_ClassManager.GetDataTableByPage(1000, 1, "parentid=3", "ordernum asc"); List<SelectListItem> item1 = new List<SelectListItem>(); var lstID = (from d in CityList.AsEnumerable() select new SelectListItem(){ Text = d["ClassName"].ToString(),Value = d["ID"].ToString() ,Selected = (d["ID"].ToString()== CityId ?true :false) }); item1.AddRange(lstID); ViewBag.SubCity = item1;
@{ if (Convert.ToInt32(HttpContext.Current.Request.Cookies["CityId"].Value) != 0) { @Html.DropDownList("SubCity", null, new { @class = "input-xlarge form-control", @disabled = "disabled" }); } else { @Html.DropDownList("SubCity", null, new { @class = "input-xlarge form-control" }) } }
点到为止