GridView字段排序

一原代码 

   public SortDirection GridViewSortDirection
        {//属性设置
            get
            {
                if (ViewState["sortDirection"] == null)
                {
                    ViewState["sortDirection"] = SortDirection.Ascending;
                }
                return (SortDirection)ViewState["sortDirection"];
            }
            set
            {
                ViewState["sortDirection"] = value;
            }
        }
        protected void GridView2_Sorting(object sender, GridViewSortEventArgs e)
        {//GridView的sorting事件
            string sortExpression = e.SortExpression;
            if (GridViewSortDirection == SortDirection.Ascending)
            {
                GridViewSortDirection = SortDirection.Descending;
                SortGridView(sortExpression, "DESC");
            }
            else
            {
                GridViewSortDirection = SortDirection.Ascending;
                SortGridView(sortExpression, "ASC");
            }
        }

        private void SortGridView(string sortExpression, string sortdirection)
        {//自定义一个函数,
            sql = string.Format("SELECT [order].ordering_time, [order].order_id, dealer.dealer_name, [order].num, [order].TotalPrice, [order].TotalVolume, [order].TotalWeight, [order].sendMoney, [order].order_state, [order].order_compele_time FROM [order] INNER JOIN dealer ON [order].dealer_id = dealer.dealer_id where [order].order_state!='" + orderState + "' and dealer.dealer_id in(select dealer_id from dealer where dealer_eare='{4}') and [order].order_id LIKE '%{0}%' and dealer.dealer_name like '%{1}%'and [order].order_state like '%{2}%' and dealer.dealer_eare like '%{3}%' ", papaValue[0], papaValue[1], papaValue[2], papaValue[5],Eare);
            OrderList OL = new OrderList();
            DataView dv = OL.getOrderListBySQL(sql);

            this.GridView1.DataSource = dv;

            dv.Sort = sortExpression + " " + sortdirection;

            GridView1.DataSource = dv;
            this.GridView1.DataBind();
        }
        protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {//翻页功能实现
            GridView1.PageIndex = e.NewPageIndex;
            // this.backdatast();
            ViewBind(papaValue);
        }

二、AllSorting设成True

三、把排序字段转成TemplateField

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值