一、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" })
                                    }
                                }

 

相关文章:

  • 2021-08-26
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-19
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案