DataGridPagerStyle 类

定义

DataGrid 控件的页导航提供样式。Specifies the style for the pager of the DataGrid control. 无法继承此类。This class cannot be inherited.

public ref class DataGridPagerStyle sealed : System::Web::UI::WebControls::TableItemStyle
public sealed class DataGridPagerStyle : System.Web.UI.WebControls.TableItemStyle
type DataGridPagerStyle = class
    inherit TableItemStyle
Public NotInheritable Class DataGridPagerStyle
Inherits TableItemStyle
继承

示例

下面的代码示例演示如何使用 DataGridPagerStyle 对象来表示 PagerStyle 属性中的页导航元素的样式。The following code example demonstrates how to use a DataGridPagerStyle object to represent the style of the pager element in the PagerStyle property. DataGridPagerStyle 对象设置分页元素的显示模式和对齐方式。The DataGridPagerStyle object sets the display mode and alignment of the paging element.

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <script language="C#" runat="server">
 
      ICollection CreateDataSource() 
      {
         DataTable dt = new DataTable();
         DataRow dr;
 
         dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
         dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
         dt.Columns.Add(new DataColumn("DateTimeValue", typeof(string)));
         dt.Columns.Add(new DataColumn("BoolValue", typeof(bool)));
 
         for (int i = 0; i < 100; i++) 
         {
            dr = dt.NewRow();
 
            dr[0] = i;
            dr[1] = "Item " + i.ToString();
            dr[2] = DateTime.Now.ToShortDateString();
            dr[3] = (i % 2 != 0) ? true : false;
 
            dt.Rows.Add(dr);
         }
 
         DataView dv = new DataView(dt);
         return dv;
      }
 
      void Page_Load(Object sender, EventArgs e) 
      {
         if (chk1.Checked)
            MyDataGrid.PagerStyle.Mode = PagerMode.NumericPages;
         else 
            MyDataGrid.PagerStyle.Mode = PagerMode.NextPrev;
 
         BindGrid();
      }
 
      void MyDataGrid_Page(Object sender, DataGridPageChangedEventArgs e) 
      {
         MyDataGrid.CurrentPageIndex = e.NewPageIndex;
         BindGrid();
      }
 
      void BindGrid() 
      {
         MyDataGrid.DataSource = CreateDataSource();
         MyDataGrid.DataBind();
         ShowStats();
      }
 
      void ShowStats() 
      {
         lblEnabled.Text = "AllowPaging is " + MyDataGrid.AllowPaging;
         lblCurrentIndex.Text = "CurrentPageIndex is " + MyDataGrid.CurrentPageIndex;
         lblPageCount.Text = "PageCount is " + MyDataGrid.PageCount;
         lblPageSize.Text = "PageSize is " + MyDataGrid.PageSize;
      }
 
 
   </script>
 
<head runat="server">
    <title>Paging with DataGrid</title>
</head>
<body>
 
   <h3>Paging with DataGrid</h3>
 
   <form id="form1" runat="server">
 
      <asp:DataGrid id="MyDataGrid" runat="server"
           AllowPaging="True"
           PageSize="10"
           PagerStyle-Mode="NumericPages"
           PagerStyle-HorizontalAlign="Right"
           OnPageIndexChanged="MyDataGrid_Page"
           BorderColor="black"
           BorderWidth="1"
           GridLines="Both"
           CellPadding="3"
           CellSpacing="0"
           Font-Names="Verdana"
           Font-Size="8pt"
           HeaderStyle-BackColor="#aaaadd"
           AlternatingItemStyle-BackColor="#eeeeee"/>
 
      <br />
 
      <asp:Checkbox id="chk1" runat="server"
           Text="Show numeric page navigation buttons"
           Font-Names="Verdana"
           Font-Size="8pt"
           AutoPostBack="true"/>
 
      <br />
 
      <table style="background-color:#eeeeee; padding:6">
         <tr>
            <td style="display:inline">
               
 
                  <asp:Label id="lblEnabled" 
                       runat="server"/><br />
                  <asp:Label id="lblCurrentIndex" 
                       runat="server"/><br />
                  <asp:Label id="lblPageCount" 
                       runat="server"/><br />
                  <asp:Label id="lblPageSize" 
                        runat="server"/><br />
 
               
            </td>
         </tr>
      </table>
 
   </form>
 
</body>
</html>

<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <script language="VB" runat="server">
 
    Function CreateDataSource() As ICollection
        Dim dt As New DataTable()
        Dim dr As DataRow
        
        dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
        dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
        dt.Columns.Add(New DataColumn("DateTimeValue", GetType(String)))
        dt.Columns.Add(New DataColumn("BoolValue", GetType(Boolean)))
        
        Dim i As Integer
        For i = 0 To 99
            dr = dt.NewRow()
            
            dr(0) = i
            dr(1) = "Item " & i.ToString()
            dr(2) = DateTime.Now.ToShortDateString()
            If i Mod 2 <> 0 Then
                dr(3) = True
            Else
                dr(3) = False
            End If
            
            dt.Rows.Add(dr)
        Next i
        
        Dim dv As New DataView(dt)
        Return dv
    End Function 'CreateDataSource

    Sub Page_Load(sender As Object, e As EventArgs)
        If chk1.Checked Then
            MyDataGrid.PagerStyle.Mode = PagerMode.NumericPages
        Else
            MyDataGrid.PagerStyle.Mode = PagerMode.NextPrev
        End If 
        BindGrid()
    End Sub 'Page_Load

    Sub MyDataGrid_Page(sender As Object, e As DataGridPageChangedEventArgs)
        MyDataGrid.CurrentPageIndex = e.NewPageIndex
        BindGrid()
    End Sub 'MyDataGrid_Page

    Sub BindGrid()
        MyDataGrid.DataSource = CreateDataSource()
        MyDataGrid.DataBind()
        ShowStats()
    End Sub 'BindGrid

    Sub ShowStats()
        lblEnabled.Text = "AllowPaging is " & MyDataGrid.AllowPaging
        lblCurrentIndex.Text = "CurrentPageIndex is " & MyDataGrid.CurrentPageIndex
        lblPageCount.Text = "PageCount is " & MyDataGrid.PageCount
        lblPageSize.Text = "PageSize is " & MyDataGrid.PageSize
    End Sub 'ShowStats
   </script>
 
<head runat="server">
    <title>Paging with DataGrid</title>
</head>
<body>
 
   <h3>Paging with DataGrid</h3>
 
   <form id="form1" runat="server">
 
      <asp:DataGrid id="MyDataGrid" runat="server"
           AllowPaging="True"
           PageSize="10"
           PagerStyle-Mode="NumericPages"
           PagerStyle-HorizontalAlign="Right"
           OnPageIndexChanged="MyDataGrid_Page"
           BorderColor="black"
           BorderWidth="1"
           GridLines="Both"
           CellPadding="3"
           CellSpacing="0"
           Font-Names="Verdana"
           Font-Size="8pt"
           HeaderStyle-BackColor="#aaaadd"
           AlternatingItemStyle-BackColor="#eeeeee"/>
 
      <br />
 
      <asp:Checkbox id="chk1" runat="server"
           Text="Show numeric page navigation buttons"
           Font-Names="Verdana"
           Font-Size="8pt"
           AutoPostBack="true"/>
 
      <br />
 
      <table style="background-color:#eeeeee; padding:6">
         <tr>
            <td style="display:inline">
               
 
                  <asp:Label id="lblEnabled" 
                       runat="server"/><br />
                  <asp:Label id="lblCurrentIndex" 
                       runat="server"/><br />
                  <asp:Label id="lblPageCount" 
                       runat="server"/><br />
                  <asp:Label id="lblPageSize" 
                        runat="server"/><br />
 
               
            </td>
         </tr>
      </table>
 
   </form>
 
</body>
</html>

注解

页导航是 DataGrid 控件上的一个元素,可用于在启用分页时链接到其他页。The pager is an element on the DataGrid control that allows you to link to other pages when paging is enabled. DataGrid 控件的 PagerStyle 属性使用此类的实例来表示页导航的样式属性。The PagerStyle property of the DataGrid control uses an instance of this class to represent the style properties for the pager.

有关分页的详细信息,请参阅 AllowPagingAllowCustomPagingFor more information on paging, see AllowPaging and AllowCustomPaging.

属性

BackColor

获取或设置 Web 服务器控件的背景色。Gets or sets the background color of the Web server control.

(继承自 Style)
BorderColor

获取或设置 Web 服务器控件的边框颜色。Gets or sets the border color of the Web server control.

(继承自 Style)
BorderStyle

获取或设置 Web 服务器控件的边框样式。Gets or sets the border style of the Web server control.

(继承自 Style)
BorderWidth

获取或设置 Web 服务器控件的边框宽度。Gets or sets the border width of the Web server control.

(继承自 Style)
CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
Container

获取包含 IContainerComponentGets the IContainer that contains the Component.

(继承自 Component)
CssClass

获取或设置由 Web 服务器控件在客户端呈现的级联样式表 (CSS) 类。Gets or sets the cascading style sheet (CSS) class rendered by the Web server control on the client.

(继承自 Style)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
Font

获取与 Web 服务器控件关联的字体属性。Gets the font properties associated with the Web server control.

(继承自 Style)
ForeColor

获取或设置 Web 服务器控件的前景色(通常是文本颜色)。Gets or sets the foreground color (typically the color of the text) of the Web server control.

(继承自 Style)
Height

获取或设置 Web 服务器控件的高度。Gets or sets the height of the Web server control.

(继承自 Style)
HorizontalAlign

获取或设置单元格内容的水平对齐方式。Gets or sets the horizontal alignment of the contents in a cell.

(继承自 TableItemStyle)
IsEmpty

保护属性。A protected property. 获取一个值,该值指示是否已在状态袋中定义任何样式元素。Gets a value indicating whether any style elements have been defined in the state bag.

(继承自 Style)
IsTrackingViewState

返回一个值,该值指示状态袋中是否有任何已定义的样式元素。Returns a value indicating whether any style elements have been defined in the state bag.

(继承自 Style)
Mode

获取或设置一个值,该值指定页导航元素是显示链接到下一页和前一页的按钮,还是显示直接与某一页链接的数值按钮。Gets or sets a value that specifies whether the pager element displays buttons that link to the next and previous page, or numeric buttons that link directly to a page.

NextPageText

获取或设置为下一页按钮显示的文本。Gets or sets the text displayed for the next page button.

PageButtonCount

获取或设置在 DataGrid 控件的页导航元素中同时显示的数值按钮的数目。Gets or sets the number of numeric buttons to display concurrently in the pager element of the DataGrid control.

Position

获取或设置 DataGrid 控件中页导航元素的位置。Gets or sets the position of the pager element in the DataGrid control.

PrevPageText

获取或设置为前一页按钮显示的文本。Gets or sets the text displayed for the previous page button.

RegisteredCssClass

获取已向控件注册的级联样式表 (CSS) 类。Gets the cascading style sheet (CSS) class that is registered with the control.

(继承自 Style)
Site

获取或设置 ISiteComponentGets or sets the ISite of the Component.

(继承自 Component)
VerticalAlign

获取或设置单元格内容的垂直对齐方式。Gets or sets the vertical alignment of the contents in a cell.

(继承自 TableItemStyle)
ViewState

获取保存样式元素的状态袋。Gets the state bag that holds the style elements.

(继承自 Style)
Visible

获取或设置一个值,该值指示是否在 DataGrid 控件中显示页导航。Gets or sets a value indicating whether the pager is displayed in the DataGrid control.

Width

获取或设置 Web 服务器控件的宽度。Gets or sets the width of the Web server control.

(继承自 Style)
Wrap

获取或设置一个值,该值指示单元格的内容在单元格中是否换行。Gets or sets a value indicating whether the contents of a cell wrap in the cell.

(继承自 TableItemStyle)

方法

AddAttributesToRender(HtmlTextWriter)

将需要呈现的 HTML 特性和样式添加到指定的 HtmlTextWriter 中。Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter. 此方法主要由控件开发人员使用。This method is primarily used by control developers.

(继承自 Style)
AddAttributesToRender(HtmlTextWriter, WebControl)

将有关水平对齐方式、垂直对齐方式和包装的信息添加到要呈现的特性列表中。Adds information about horizontal alignment, vertical alignment, and wrap to the list of attributes to render.

(继承自 TableItemStyle)
CopyFrom(Style)

将指定的 Style 对象的样式复制到 DataGridPagerStyle 类的此实例中。Copies the style of the specified Style object into this instance of the DataGridPagerStyle class.

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(继承自 Component)
Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(继承自 Component)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FillStyleAttributes(CssStyleCollection, IUrlResolutionService)

将指定对象的样式属性添加到 CssStyleCollection 对象。Adds the specified object's style properties to a CssStyleCollection object.

(继承自 Style)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetStyleAttributes(IUrlResolutionService)

检索实现了 CssStyleCollection 的指定对象的 IUrlResolutionService 对象。Retrieves the CssStyleCollection object for the specified IUrlResolutionService-implemented object.

(继承自 Style)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
LoadViewState(Object)

加载以前保存的状态。Loads the previously saved state.

(继承自 Style)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
MergeWith(Style)

将指定的 Style 对象的样式与 DataGridPagerStyle 类的此实例合并在一起。Merges the style of the specified Style object with this instance of the DataGridPagerStyle class.

Reset()

DataGridPagerStyle 对象还原为其默认值。Restores the DataGridPagerStyle object to its default values.

SaveViewState()

受保护的方法。A protected method. 保存在调用 TrackViewState() 方法后已修改的任何状态。Saves any state that has been modified after the TrackViewState() method was invoked.

(继承自 Style)
SetBit(Int32)

受保护的内部方法。A protected internal method. 设置一个内部位屏蔽字段以指示存储在状态袋中的样式属性。Sets an internal bitmask field that indicates the style properties that are stored in the state bag.

(继承自 Style)
SetDirty()

标记 Style 以便在视图状态中记录其状态。Marks the Style so that its state will be recorded in view state.

(继承自 Style)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Style)
TrackViewState()

受保护的方法。A protected method. 标记跟踪控件状态更改的起始点。Marks the beginning for tracking state changes on the control. 跟踪开始之后所做的任何更改都将被跟踪并保存到控件视图状态中。Any changes made after tracking has begun will be tracked and saved as part of the control view state.

(继承自 Style)

事件

Disposed

在通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)

显式接口实现

IStateManager.IsTrackingViewState

获取一个值,该值指示服务器控件是否在跟踪其视图状态更改。Gets a value that indicates whether a server control is tracking its view state changes.

(继承自 Style)
IStateManager.LoadViewState(Object)

加载以前保存的状态。Loads the previously saved state.

(继承自 Style)
IStateManager.SaveViewState()

返回包含状态更改的对象。Returns the object containing state changes.

(继承自 Style)
IStateManager.TrackViewState()

开始跟踪状态更改。Starts tracking state changes.

(继承自 Style)

适用于

另请参阅