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";
            }
  • 相关阅读:
    (转)使用 PyInstaller 把python程序 .py转为 .exe 可执行程序
    (转)使用 python Matplotlib 库绘图
    使用Matplotlib画图系列(一)
    Numpy常用金融计算(一)
    Windows中安装Linux子系统的详细步骤
    Centos7+Postfix+Dovecot实现内网邮件收发 风行天下
    centos7系统防火墙端口转发 风行天下
    Centos7+Postfix+Dovecot实现内网邮件收发
    centos7的路径含有空格Linux命令使用时路径存在空格、特殊符号(如、@等等) 风行天下
    zabbix无法使用Detect operating system [zabbix] 风行天下
  • 原文地址:https://www.cnblogs.com/haoxr/p/3054296.html
Copyright © 2011-2022 走看看