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";
            }
  • 相关阅读:
    综合日语第一册第十课
    综合日语第一册第九课
    荒木毬菜 小情歌日文版
    c# 匿名函数
    字典取KEY,占位符,延迟刷新
    flash GC
    自定义滤镜 ColorMatrixFilter
    sql join
    NSLog Release
    Windows 运行中的命令
  • 原文地址:https://www.cnblogs.com/haoxr/p/3054296.html
Copyright © 2011-2022 走看看