ASPxGridView自定义分页,点击标题排序
2015-11-17 14:00
901 查看
使用ASPxGridView和ASPxPager,进行自定义分页。
前台代码:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" Width="720" ClientInstanceName="ASPxGridView1" OnBeforeColumnSortingGrouping="ASPxGridView1_BeforeColumnSortingGrouping" >
<SettingsPager Visible="False" Mode="ShowAllRecords"/>
<SettingsText EmptyDataRow="没有数据"></SettingsText>
<SettingsLoadingPanel Text="正在加载..."></SettingsLoadingPanel>
<Settings ShowVerticalScrollBar="true" ShowHorizontalScrollBar="true" ShowFilterRow="True" ShowGroupPanel="True" ShowFilterRowMenu="True" ShowHeaderFilterButton="True" ShowFooter="true" />
<Styles>
<Header ImageSpacing="5px" SortingImageSpacing="5px" HorizontalAlign="Center"/>
<LoadingPanel ImageSpacing="10px"/>
<AlternatingRow Enabled="True" />
</Styles>
<Columns>
<dx:GridViewDataTextColumn Caption="序号" FieldName="row_no" VisibleIndex="0" FixedStyle="Left" CellStyle-BackColor="#ffffd6" />
<dx:GridViewDataTextColumn Caption="Delivery No" FieldName="delivery_no" VisibleIndex="1" FixedStyle="Left" CellStyle-BackColor="#ffffd6" />
<dx:GridViewDataTextColumn Caption="收货仓" FieldName="wh_name" VisibleIndex="2"/>
<dx:GridViewDataTextColumn Caption="产品大类" FieldName="product_type" VisibleIndex="3"/>
<dx:GridViewDataColumn Caption="Details" VisibleIndex="4">
<DataItemTemplate>
<a href="default2.aspx?AuctionID=<%# Eval("order_no")%>" target="_blank" >跟踪</a>
</DataItemTemplate>
</dx:GridViewDataColumn>
</Columns>
<TotalSummary>
<dx:ASPxSummaryItem FieldName="order_no" SummaryType="Count" DisplayFormat="行计数{0}"/>
</TotalSummary>
</dx:ASPxGridView>
<dx:ASPxPager ID="ASPxPager1" runat="server" OnPageIndexChanged="ASPxPager1_PageIndexChanged">
<Summary AllPagesText="分页{0} - {1} (总{2}条)" Text="当前第{0}页,共{1}页 (共{2}条)" />
<LastPageButton Visible="True">
</LastPageButton>
<FirstPageButton Visible="True">
</FirstPageButton>
</dx:ASPxPager>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ASPxPager1" EventName="PageIndexChanged" />
</Triggers>
</asp:UpdatePanel>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData(1);
}
}
private void BindData(int cur_page)
{
string sort = sSortDirection;
if (string.IsNullOrEmpty(sort))
sort = "asc";
DataSet ds = ExecuteSqlGetDS("exec p_get_list @page_size=" + ASPxPager1.ItemsPerPage + ",@page_number=" + (cur_page) + ",@query_value=N'3||1',@sort=N'" + SortFieldName + " " + sort + "'");
if (ds != null && ds.Tables.Count > 0)
{
ASPxGridView1.DataSource = ds.Tables[0];
ASPxGridView1.DataBind();
ASPxPager1.ItemCount = (int)ds.Tables[0].Rows[0][0];
}
else
{
ASPxPager1.ItemCount = 0;
}
}
protected void ASPxGridView1_BeforeColumnSortingGrouping(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewBeforeColumnGroupingSortingEventArgs e)
{
switch (e.Column.SortOrder)
{
case DevExpress.Data.ColumnSortOrder.Ascending:
sSortDirection = "asc";
break;
case DevExpress.Data.ColumnSortOrder.Descending:
sSortDirection = "desc";
break;
}
SortFieldName = e.Column.FieldName;
BindData(1);
}
protected void ASPxPager1_PageIndexChanged(object sender, EventArgs e)
{
BindData(ASPxPager1.PageIndex + 1);
}
protected string SortFieldName
{
get
{
if (Session["SortFieldName"] == null)
Session["SortFieldName"] = "delivery_no";
return Session["SortFieldName"].ToString();
}
set
{
Session["SortFieldName"] = value;
}
}
protected string sSortDirection
{
get
{
if (Session["SortDirection"] == null)
Session["SortDirection"] = "asc";
return Session["SortDirection"].ToString();
}
set
{
Session["SortDirection"] = value;
}
}
前台代码:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" Width="720" ClientInstanceName="ASPxGridView1" OnBeforeColumnSortingGrouping="ASPxGridView1_BeforeColumnSortingGrouping" >
<SettingsPager Visible="False" Mode="ShowAllRecords"/>
<SettingsText EmptyDataRow="没有数据"></SettingsText>
<SettingsLoadingPanel Text="正在加载..."></SettingsLoadingPanel>
<Settings ShowVerticalScrollBar="true" ShowHorizontalScrollBar="true" ShowFilterRow="True" ShowGroupPanel="True" ShowFilterRowMenu="True" ShowHeaderFilterButton="True" ShowFooter="true" />
<Styles>
<Header ImageSpacing="5px" SortingImageSpacing="5px" HorizontalAlign="Center"/>
<LoadingPanel ImageSpacing="10px"/>
<AlternatingRow Enabled="True" />
</Styles>
<Columns>
<dx:GridViewDataTextColumn Caption="序号" FieldName="row_no" VisibleIndex="0" FixedStyle="Left" CellStyle-BackColor="#ffffd6" />
<dx:GridViewDataTextColumn Caption="Delivery No" FieldName="delivery_no" VisibleIndex="1" FixedStyle="Left" CellStyle-BackColor="#ffffd6" />
<dx:GridViewDataTextColumn Caption="收货仓" FieldName="wh_name" VisibleIndex="2"/>
<dx:GridViewDataTextColumn Caption="产品大类" FieldName="product_type" VisibleIndex="3"/>
<dx:GridViewDataColumn Caption="Details" VisibleIndex="4">
<DataItemTemplate>
<a href="default2.aspx?AuctionID=<%# Eval("order_no")%>" target="_blank" >跟踪</a>
</DataItemTemplate>
</dx:GridViewDataColumn>
</Columns>
<TotalSummary>
<dx:ASPxSummaryItem FieldName="order_no" SummaryType="Count" DisplayFormat="行计数{0}"/>
</TotalSummary>
</dx:ASPxGridView>
<dx:ASPxPager ID="ASPxPager1" runat="server" OnPageIndexChanged="ASPxPager1_PageIndexChanged">
<Summary AllPagesText="分页{0} - {1} (总{2}条)" Text="当前第{0}页,共{1}页 (共{2}条)" />
<LastPageButton Visible="True">
</LastPageButton>
<FirstPageButton Visible="True">
</FirstPageButton>
</dx:ASPxPager>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ASPxPager1" EventName="PageIndexChanged" />
</Triggers>
</asp:UpdatePanel>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData(1);
}
}
private void BindData(int cur_page)
{
string sort = sSortDirection;
if (string.IsNullOrEmpty(sort))
sort = "asc";
DataSet ds = ExecuteSqlGetDS("exec p_get_list @page_size=" + ASPxPager1.ItemsPerPage + ",@page_number=" + (cur_page) + ",@query_value=N'3||1',@sort=N'" + SortFieldName + " " + sort + "'");
if (ds != null && ds.Tables.Count > 0)
{
ASPxGridView1.DataSource = ds.Tables[0];
ASPxGridView1.DataBind();
ASPxPager1.ItemCount = (int)ds.Tables[0].Rows[0][0];
}
else
{
ASPxPager1.ItemCount = 0;
}
}
protected void ASPxGridView1_BeforeColumnSortingGrouping(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewBeforeColumnGroupingSortingEventArgs e)
{
switch (e.Column.SortOrder)
{
case DevExpress.Data.ColumnSortOrder.Ascending:
sSortDirection = "asc";
break;
case DevExpress.Data.ColumnSortOrder.Descending:
sSortDirection = "desc";
break;
}
SortFieldName = e.Column.FieldName;
BindData(1);
}
protected void ASPxPager1_PageIndexChanged(object sender, EventArgs e)
{
BindData(ASPxPager1.PageIndex + 1);
}
protected string SortFieldName
{
get
{
if (Session["SortFieldName"] == null)
Session["SortFieldName"] = "delivery_no";
return Session["SortFieldName"].ToString();
}
set
{
Session["SortFieldName"] = value;
}
}
protected string sSortDirection
{
get
{
if (Session["SortDirection"] == null)
Session["SortDirection"] = "asc";
return Session["SortDirection"].ToString();
}
set
{
Session["SortDirection"] = value;
}
}
相关文章推荐
- Office 365 Starter Project for ASP.NET MVC
- MVC6上传图片
- MVC4学习笔记01
- ASP.NET连接数据库并获取数据方法总结
- js asp.net获取时间戳
- Asp.Net 之 汉字转拼音
- asp.net编程获取项目根目录实现方法集合
- ASP.NET 5 Web Api 集成测试
- 界面控件Essential Studio for ASP.NET MVC 2015 v3正式发布[附下载]
- Orchard 与 ABP架构比较 (aspnetboilerplate)
- asp.net编程获取项目根目录实现方法集合
- ASP.NET连接数据库并获取数据方法总结
- asp.net微信开发(消息应答)
- asp.net微信开发(自定义会话管理)
- Dreamweaver制作ASP网页用DSN链接Access数据库的方法及上传修改
- plantomjs&casperjs
- asp.net字符串的数学表达式计算结果
- 利用Aspose.Word控件实现Word文档的操作
- ASP.net 手机归属地查询(Web Service)
- asp.net mvc webconfig配置文件操作