zoukankan      html  css  js  c++  java
  • 二、初学.NET—Gridview的排序

    前端:.aspx

    首先设置GirdView的AllowSorting属性为True

    <asp:GridView ID="gv_ReviewIndex" runat="server"  AllowPaging="True" AllowSorting="True" />

    每一列,包括模板列设置SortExpression需要排序的字段名

    <asp:TemplateField HeaderText="评审分数" SortExpression="ReviewSumScore" >

              <ItemTemplate>

                    <asp:Label ID="lb_ReviewScore" runat="server" Text='<%#Eval("ReviewSumScore") %>'></asp:Label>

              </ItemTemplate>

               <FooterTemplate>

                     <asp:Label ID="Label3" runat="server" Text=""></asp:Label>

              </FooterTemplate>

              </asp:TemplateField>

    后台代码:.aspx.cs 指定Sorting事件处理代码

    protected void gv_ReviewIndex_Sorting(object sender, GridViewSortEventArgs e)

        {

            if (ViewState["SortExpresstion"] != null)

            {

                if (ViewState["SortExpresstion"].ToString() == e.SortExpression)

                {

                    if (ViewState["SortDirection"].ToString() == "ASC")

                    {

                        ViewState["SortDirection"] = "DESC";

                    }

                    else

                    {

                        ViewState["SortDirection"] = "ASC";

                    }

                }

                else

                {

                    ViewState["SortExpresstion"] = e.SortExpression;

                    ViewState["SortDirection"] = "ASC";

                }

            }

            else

            {

                ViewState["SortExpresstion"] = e.SortExpression;

                ViewState["SortDirection"] = "ASC";

            }

            SetBind();

        }

    修改GridView控件绑定代码:

    private void SetBind()

        {

            DataSet ds = new DataSet();

            using (SqlConnection conn = new SqlConnection(sConnectionString))

            {

               SqlDataAdapter da = new SqlDataAdapter("select * from  tbReview'", conn);

                da.Fill(ds);

             }

            DataView dv = new DataView(ds.Tables[0]);

            if (ViewState["SortExpresstion"] != null)

                dv.Sort = ViewState["SortExpresstion"].ToString() + " " + ViewState["SortDirection"].ToString();

            gv_ReviewIndex.DataSource = dv;

            gv_ReviewIndex.DataBind();

     

        }

  • 相关阅读:
    Cocos Creator 图集 (TexturePacker、自动图集功能 、压缩纹理)
    Cocos Creator 下载不同版本引擎
    Cocos Creator 源码 (位置,阅读、修改)
    Laya3D Unity商店免费下载3D资源使用(Unity插件支持哪些导出)
    三 Laya3D 加载资源 (场景/预设/模型网格/材质/动画文件/贴图/粒子)
    二 Laya3D github demo下载并使用
    一 Laya3D Unity下载和插件安装
    AndroidUI设计之布局-详细解析布局实现
    Android 监听ScrollView的滑动
    【Android进阶】Android程序与JavaScript之间的简单调用
  • 原文地址:https://www.cnblogs.com/liuyuanhao/p/3012941.html
Copyright © 2011-2022 走看看