文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>GridView标题分页,泛型作为数据源!

GridView标题分页,泛型作为数据源!

时间:2011-03-17  来源:rgzazq

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                #region 标题排序变量
                ViewState["sortName"] = "CreateDate";
                ViewState["sortOrder"] = "Desc";
                #endregion  

    }

  }

 protected void grvDetail_Sorting(object sender, GridViewSortEventArgs e)
        {
            ViewState["sortName"] = e.SortExpression.ToString(); //排序字段
            if (ViewState["sortOrder"].ToString() == "Desc")
                ViewState["sortOrder"] = "Asc";
            else
                ViewState["sortOrder"] = "Desc";

            this.BindData();
        }

   /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindData()
        {
            Bll_Brand bll = new Bll_Brand();
            List<T_Brand> datalist = bll.GetBrandInfo();//你查询得到的泛型数据

            #region 标题排序
            var lst = datalist;
            if (ViewState["sortName"] != null && ViewState["sortOrder"] != null)
            {
                string sortName = ViewState["sortName"].ToString().Trim();
                string sortOrder = ViewState["sortOrder"].ToString().Trim();
                PropertyInfo prop = typeof(T_Brand).GetProperty(sortName); //T_Brand是Model层的一个类
                if (sortOrder == "Asc")
                {
                    lst = datalist.OrderBy(T_Brand => prop.GetValue(T_Brand, null)).ToList();
                }
                else if (sortOrder == "Desc")
                {
                    lst = datalist.OrderByDescending(T_Brand => prop.GetValue(T_Brand, null)).ToList();
                }
            }
            else
            {
                Response.Write("<script>alert('标题排序所需条件部分丢失,当前为默认排序!');</script>");
            }
            if (lst != null)
            {
                rowcount = lst.Count;
            }

            #endregion

            this.grvDetail.DataSource = lst;
            this.grvDetail.DataBind();
        }

OK 搞定!!!

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载