首页 > 代码库 > dynamic小用

dynamic小用

        /// <summary>
        /// 设置下拉框第一项
        /// </summary>
        /// <param name="lst">数据源列表</param>
        private void SetFirstItem(List<dynamic> lst)
        {
            string sFlag = Request["flag"];
            switch (sFlag)
            {
                case "0":
                    lst.Insert(0, new { id = -999, text = "--全部--", selected = true });
                    break;
                case "1":
                    lst.Insert(0, new { id = -999, text = "--请选择--", selected = true });
                    break;
                default:
                    break;
            }
        }

        // 性别
        public void BindGender()
        {
            List<dynamic> lst = new List<dynamic>();
            lst.Add(new { id = 0, text = "未知" });
            lst.Add(new { id = 1, text = "" });
            lst.Add(new { id = 2, text = "" });
            SetFirstItem(lst);
            Response.Write(JsonHelper.ToJson(lst));
        }

 

dynamic小用