对GridView、DetailsView 和 FormView 控件分页属性的PagerSettings类的设置

来源:互联网 发布:关系数据库逻辑模型 编辑:程序博客网 时间:2024/06/05 11:13

如果想让分页导航加上图片形式或比如上一页下一页,这种样式,那就要在<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 值时,您可以通过设置下表中所示的属性来自定义非数字按钮的文字。

属性

说明

FirstPageText

第一页按钮的文字。

PreviousPageText

上一页按钮的文字。

NextPageText

下一页按钮的文字。

LastPageText

最后一页按钮的文字。

或者,您可以通过设置下表中所示的属性为非数字按钮显示图像。

属性

说明

FirstPageImageUrl

为第一页按钮显示的图像的 URL。

PreviousPageImageUrl

为上一页按钮显示的图像的 URL。

NextPageImageUrl

为下一页按钮显示的图像的 URL。

LastPageImageUrl

为最后一页按钮显示的图像的 URL。

Note注意

在图像属性设置后,相应的文字属性会作为图像的替换文字。例如,在设置 FirstPageImageUrl 属性后,由 FirstPageText 属性指定的文字将显示为图像的替换文字。在支持工具提示的浏览器上,此文本也显示为相应按钮的工具提示。

在 Mode 属性设置为 Numeric 或 NumericFirstLast 值时,您可以通过设置 PageButtonCount 属性,指定要在页导航中显示的页按钮的数量。

页导航可以显示在控件的顶部、底部或同时显示在顶部和底部。若要指定页导航的位置,请设置 Position 属性。若要显示或隐藏页导航,请使用 Visible 属性。

下面是一个关于PagerSettings的事例

<%@ Page language="C#" %>

<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 类型公开的成员。

Collapse 图像 公共构造函数

  名称 说明 Public method PagerSettings 初始化 PagerSettings 类的新实例。 页首

Collapse 图像 公共属性

  名称 说明 Public property FirstPageImageUrl 获取或设置为第一页按钮显示的图像的 URL。 Public property FirstPageText 获取或设置为第一页按钮显示的文字。 Public property LastPageImageUrl 获取或设置为最后一页按钮显示的图像的 URL。 Public property LastPageText 获取或设置为最后一页按钮显示的文字。 Public property Mode 获取或设置支持分页的控件中的页导航控件的显示模式。 Public property NextPageImageUrl 获取或设置为下一页按钮显示的图像的 URL。 Public property NextPageText 获取或设置为下一页按钮显示的文字。 Public property PageButtonCount 获取或设置在 Mode 属性设置为 NumericNumericFirstLast 值时页导航中显示的页按钮的数量。 Public property Position 获取或设置一个值,该值指定页导航的显示位置。 Public property PreviousPageImageUrl 获取或设置为上一页按钮显示的图像的 URL。 Public property PreviousPageText 获取或设置为上一页按钮显示的文字。 Public property Visible 获取或设置一个值,该值指示是否在支持分页的控件中显示分页控件。 页首

Collapse 图像 公共方法 (请参见 受保护的方法 )

  名称 说明 Public method Equals  已重载。 确定两个 Object 实例是否相等。 (从 Object 继承。) Public method GetHashCode  用作特定类型的哈希函数。GetHashCode 适合在哈希算法和数据结构(如哈希表)中使用。 (从 Object 继承。) Public method GetType  获取当前实例的 Type。 (从 Object 继承。) Public method Static ReferenceEquals  确定指定的 Object 实例是否是相同的实例。 (从 Object 继承。) Public method ToString 已重写。 检索 PagerSettings 对象的字符串表示形式。 页首

Collapse 图像 受保护的方法

  名称 说明 Protected method Finalize  允许 Object 在“垃圾回收”回收 Object 之前尝试释放资源并执行其他清理操作。 (从 Object 继承。) Protected method MemberwiseClone  创建当前 Object 的浅表副本。 (从 Object 继承。) 页首

Collapse 图像 公共事件

  名称 说明 Public event PropertyChanged 当 PagerSettings 对象的属性更改值时发生。 页首

Collapse 图像 显式接口实现

  名称 说明 Explicit interface implementation Method System.Web.UI.IStateManager.LoadViewState 加载以前保存的 PagerSettings 对象的视图状态。 Explicit interface implementation Method System.Web.UI.IStateManager.SaveViewState 保存 PagerSettings 对象的当前视图状态。 Explicit interface implementation Method System.Web.UI.IStateManager.TrackViewState 标记开始跟踪并将视图状态更改保存到 PagerSettings 对象的起始点。 Explicit interface implementation Property System.Web.UI.IStateManager.IsTrackingViewState 有关此成员的说明,请参见 IsTrackingViewState。 页首