如果想让分页导航加上图片形式或比如上一页下一页,这种样式,那就要在<GridView>写在这里面</GridView>控件中加上<PagerSettings></PagerSettings>,
例如:<PagerSettings Mode="NextPreviousFirstLast" FirstPageText="首页" LastPageText="尾页" PreviousPageText="上一页" NextPageText="下一页" PageButtonCount="5" /> 其实如果你不想有分页导航的话,你再加一个 Visible="false" 就没有分页导航的。
支持分页的控件(如 GridView、DetailsView 和 FormView 控件)可以显示一组称为“页导航”的控件,用户使用这些控件可以在控件内的页面之间导航。这些控件使用 PagerSettings 类来表示页导航的属性。
页导航支持几种不同的显示模式。若要指定页导航的显示模式,请设置 Mode 属性。下表介绍了这几种不同的模式。
模式 | 说明 |
---|---|
NextPrevious | 上一页按钮和下一页按钮。 |
NextPreviousFirstLast | 上一页按钮、下一页按钮、第一页按钮和最后一页按钮。 |
Numeric | 可直接访问页面的带编号的链接按钮。 |
NumericFirstLast | 带编号的链接按钮、第一个链接按钮和最后一个链接按钮。 |
在 Mode 属性设置为 NextPrevious、NextPreviousFirstLast 或 NumericFirstLast 值时,您可以通过设置下表中所示的属性来自定义非数字按钮的文字。
属性 | 说明 |
---|---|
第一页按钮的文字。 | |
上一页按钮的文字。 | |
下一页按钮的文字。 | |
最后一页按钮的文字。 |
或者,您可以通过设置下表中所示的属性为非数字按钮显示图像。
属性 | 说明 |
---|---|
为第一页按钮显示的图像的 URL。 | |
为上一页按钮显示的图像的 URL。 | |
为下一页按钮显示的图像的 URL。 | |
为最后一页按钮显示的图像的 URL。 |
注意 |
---|
在图像属性设置后,相应的文字属性会作为图像的替换文字。例如,在设置 FirstPageImageUrl 属性后,由 FirstPageText 属性指定的文字将显示为图像的替换文字。在支持工具提示的浏览器上,此文本也显示为相应按钮的工具提示。 |
在 Mode 属性设置为 Numeric 或 NumericFirstLast 值时,您可以通过设置 PageButtonCount 属性,指定要在页导航中显示的页按钮的数量。
页导航可以显示在控件的顶部、底部或同时显示在顶部和底部。若要指定页导航的位置,请设置 Position 属性。若要显示或隐藏页导航,请使用 Visible 属性。
下面是一个关于PagerSettings的事例
< html >
< body >
< form runat ="server" >
< h3 > PagerSetting Example </ h3 >
< asp:gridview id ="CustomerGridView"
datasourceid ="CustomerDataSource"
autogeneratecolumns ="true"
datakeynames ="CustomerID"
allowpaging ="true"
runat ="server" >
< pagersettings mode ="NextPreviousFirstLast"
firstpagetext ="First"
lastpagetext ="Last"
nextpagetext ="Next"
previouspagetext ="Prev"
position ="Bottom" />
</ asp:gridview >
< br />
< asp:label id ="MessageLabel"
forecolor ="Red"
runat ="server" />
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
< asp:sqldatasource id ="CustomerDataSource"
selectcommand ="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring ="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat ="server" />
</ form >
</ body >
</ html >
========================================
PagerSettings 的成员
下表列出了由 PagerSettings 类型公开的成员。
公共构造函数
名称 | 说明 | |
---|---|---|
PagerSettings | 初始化 PagerSettings 类的新实例。 |
公共属性
名称 | 说明 | |
---|---|---|
FirstPageImageUrl | 获取或设置为第一页按钮显示的图像的 URL。 | |
FirstPageText | 获取或设置为第一页按钮显示的文字。 | |
LastPageImageUrl | 获取或设置为最后一页按钮显示的图像的 URL。 | |
LastPageText | 获取或设置为最后一页按钮显示的文字。 | |
Mode | 获取或设置支持分页的控件中的页导航控件的显示模式。 | |
NextPageImageUrl | 获取或设置为下一页按钮显示的图像的 URL。 | |
NextPageText | 获取或设置为下一页按钮显示的文字。 | |
PageButtonCount | 获取或设置在 Mode 属性设置为 Numeric 或 NumericFirstLast 值时页导航中显示的页按钮的数量。 | |
Position | 获取或设置一个值,该值指定页导航的显示位置。 | |
PreviousPageImageUrl | 获取或设置为上一页按钮显示的图像的 URL。 | |
PreviousPageText | 获取或设置为上一页按钮显示的文字。 | |
Visible | 获取或设置一个值,该值指示是否在支持分页的控件中显示分页控件。 |
公共方法 (请参见 受保护的方法 )
名称 | 说明 | |
---|---|---|
Equals | 已重载。 确定两个 Object 实例是否相等。 (从 Object 继承。) | |
GetHashCode | 用作特定类型的哈希函数。 GetHashCode 适合在哈希算法和数据结构(如哈希表)中使用。 (从 Object 继承。) | |
GetType | 获取当前实例的 Type 。 (从 Object 继承。) | |
ReferenceEquals | 确定指定的 Object 实例是否是相同的实例。 (从 Object 继承。) | |
ToString | 已重写。 检索 PagerSettings 对象的字符串表示形式。 |
受保护的方法
名称 | 说明 | |
---|---|---|
Finalize | 允许 Object 在“垃圾回收”回收 Object 之前尝试释放资源并执行其他清理操作。 (从 Object 继承。) | |
MemberwiseClone | 创建当前 Object 的浅表副本。 (从 Object 继承。) |
公共事件
名称 | 说明 | |
---|---|---|
PropertyChanged | 当 PagerSettings 对象的属性更改值时发生。 |
显式接口实现
名称 | 说明 | |
---|---|---|
System.Web.UI.IStateManager.LoadViewState | 加载以前保存的 PagerSettings 对象的视图状态。 | |
System.Web.UI.IStateManager.SaveViewState | 保存 PagerSettings 对象的当前视图状态。 | |
System.Web.UI.IStateManager.TrackViewState | 标记开始跟踪并将视图状态更改保存到 PagerSettings 对象的起始点。 | |
System.Web.UI.IStateManager.IsTrackingViewState | 有关此成员的说明,请参见 IsTrackingViewState 。 |