Welcome 微信登录

首页 / 网页编程 / ASP.NET / ASP.NET 2.0数据教程之二十四: 分页和排序报表数据

ASP.NET 2.0数据教程之二十四: 分页和排序报表数据2010-08-09 翻译:cnblogs LoveCherry返回“”

导言

分页和排序是在WEB应用程序中展现数据常见的功能。比如,当我 们在一个网上书店搜索ASP.NET书籍的时候,可能有几百本相关书籍,但是我们只 希望每页显示10条有效记录。而且,我们还希望结果能根据标题、价格、页数和 作者等等来进行排序。过去的23个教程中我们研究了如何建立各种报表,包括在 界面上添加编辑和删除数据。但是我们没有研究如何对数据进行排序,对于分页 我们也仅在研究DetailsView和FormView控件的时候看到。

Step 1:添加分 页和排序页面

在我们开始以前,首先让我们花些时间来添加包括本篇在内 的最近四篇教程需要用到的页面。我们先在项目中新建一个称作 PagingAndSorting的文件夹,接下来,为目录新增以下几个页面,并配置为使用 Site.master母板页。

Default.aspx

SimplePagingSorting.aspx

EfficientPaging.aspx

SortParameter.aspx

CustomSortingUI.aspx

图1:创建一个PagingAndSorting文件夹并且添加教程的页面

下 一步,让我们打开Default.aspx页面并且从UserControls中拖拽 SectionLevelTutorialListing.ascx用户控件到设计界面。我们在母板页和站点 导航教程中创建的这个用户控件遍历站点地图并且以符号列表形式把它们呈现出 来。

图2:把SectionLevelTutorialListing.ascx用户控件加入 Default.aspx

要让显示我们将要创建的分页和排序教程,我们需要把他们 加入站点地图中。打开Web.sitemap文件并且把下列代码加在“编辑、插入 和删除”siteMapNode标记之后:

<siteMapNode title="Paging and Sorting" url="~/PagingAndSorting/Default.aspx"
description="Samples of Reports that Provide Paging and Sorting Capabilities">
<siteMapNode url="~/PagingAndSorting/SimplePagingSorting.aspx"
title="Simple Paging &amp; Sorting Examples"
description="Examines how to add simple paging and sorting support." />
<siteMapNode url="~/PagingAndSorting/EfficientPaging.aspx"
title="Efficiently Paging Through Large Result Sets"
description="Learn how to efficiently page through large result sets." />
<siteMapNode url="~/PagingAndSorting/SortParameter.aspx"
title="Sorting Data at the BLL or DAL"
description="Illustrates how to perform sorting logic in the Business Logic
Layer or Data Access Layer." />
<siteMapNode url="~/PagingAndSorting/CustomSortingUI.aspx"
title="Customizing the Sorting User Interface"
description="Learn how to customize and improve the sorting user interface." />
</siteMapNode>

图3:更新站点地图使之包含新的页面