zoukankan      html  css  js  c++  java
  • asp.net DataGrid排序

    前台代码:

    View Code
    <%@ Register Assembly="WY.Web.Common" Namespace="WY.Web.Common.WebControls" TagPrefix="cc1" %>
     <cc1:DataGrid ID="DataGrid1" runat="server"  AllowCustomPaging="True" 
                    onitemdatabound="DataGrid1_ItemDataBound">
                <Columns>                                  
                     <asp:TemplateColumn SortExpression="Date" HeaderText="日期" ItemStyle-Width="140">
                        <ItemTemplate>
                           <a href="javascript:void(0)" onclick="doAdd('workrecordedit.aspx?id=<%#Utils.NvStr(Eval("Date")) %>','填写日报',980,560)" ><%#Utils.NvStr(Eval("Date")) %></a>
                        </ItemTemplate> 
                    </asp:TemplateColumn>         
                    <asp:BoundColumn DataField="Type" SortExpression="Type" HeaderText="日期种类" ItemStyle-Width = "140"></asp:BoundColumn>
                    <asp:BoundColumn DataField="Content" SortExpression="Content" HeaderText="工作内容"></asp:BoundColumn>
                    <asp:BoundColumn DataField="Record" SortExpression="Record" HeaderText="考勤记录" ItemStyle-Width="200"></asp:BoundColumn>                                
               </Columns>
            </cc1:DataGrid>

    CS:

    View Code
      protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                InitializeComponent();
            }
    
            private void InitializeComponent()
            {
                this.DataGrid1.SortCommand += new DataGridSortCommandEventHandler(DataGrid_SortCommand);
                this.DataGrid1.PageIndexChanged += new DataGridPageChangedEventHandler(DataGrid_PageIndexChanged);
                this.DataGrid1.GoToPagerButton.Click += new EventHandler(GoToPagerButton_Click);
    
                this.DataGrid1.AllowCustomPaging = true;
                this.DataGrid1.AllowSorting = true;
                this.DataGrid1.SaveDSViewState = true;
            }
    
            public void GoToPagerButton_Click(object sender, EventArgs e)
            {
                try
                {
                    BindData();
                }
                catch { }
            }
    
            public void DataGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
            {
                try
                {
                    ((WY.Web.Common.WebControls.DataGrid)source).CurrentPageIndex = e.NewPageIndex;
                    BindData();
                }
                catch { }
            }
    
            protected void DataGrid_SortCommand(object source, DataGridSortCommandEventArgs e)
            {
                ((WY.Web.Common.WebControls.DataGrid)source).Sort = e.SortExpression.ToString();
                BindData();
            }
    View Code
     DataView dv = getNewDatatable(dtb, j, dts, DataGrid1).DefaultView;
                if (!string.IsNullOrEmpty(((WY.Web.Common.WebControls.DataGrid)DataGrid1).Sort))
                {
                   // dv.Sort = ((WY.Web.Common.WebControls.DataGrid)DataGrid1).Sort + " " + DataGrid1.DataGridSortType;
                    dv.Sort = ((WY.Web.Common.WebControls.DataGrid)DataGrid1).Sort + " " + DataGrid1.GetDataGridSortType();
                }
                DataGrid1.DataSource = dv;
                DataGrid1.DataBind();
    View Code
     public string GetDataGridSortType()
            {
                object obj = ViewState["DataGridSortType"];
                string ascordesc = obj == null ? "ASC" : (string)obj;
                return ascordesc == "ASC" ? "DESC" : "ASC";
            }
  • 相关阅读:
    ELK+Kafka集群日志分析系统
    Centos 6.5 部署 redmine 3.3
    Centos 6.5 搭建l2tp 服务端和客户端
    Logstash之multiline 插件
    MYSQL MHA
    windows上给yii2安装插件
    YII2框架的安装
    Apache服务器配置项和虚拟机配置
    浮点数的比较
    微信自定义菜单总结
  • 原文地址:https://www.cnblogs.com/haoxr/p/3054296.html
Copyright © 2011-2022 走看看