DataGridPagerStyle DataGridPagerStyle DataGridPagerStyle DataGridPagerStyle Class

Definition

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
Inheritance

Examples

The following code example demonstrates how to use a DataGridPagerStyle object to represent the style of the pager element in the PagerStyle property. 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>

Remarks

The pager is an element on the DataGrid control that allows you to link to other pages when paging is enabled. The PagerStyle property of the DataGrid control uses an instance of this class to represent the style properties for the pager.

For more information on paging, see AllowPaging and AllowCustomPaging.

Properties

BackColor BackColor BackColor BackColor

Gets or sets the background color of the Web server control.

(Inherited from Style)
BorderColor BorderColor BorderColor BorderColor

Gets or sets the border color of the Web server control.

(Inherited from Style)
BorderStyle BorderStyle BorderStyle BorderStyle

Gets or sets the border style of the Web server control.

(Inherited from Style)
BorderWidth BorderWidth BorderWidth BorderWidth

Gets or sets the border width of the Web server control.

(Inherited from Style)
CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

Gets the IContainer that contains the Component.

(Inherited from Component)
CssClass CssClass CssClass CssClass

Gets or sets the cascading style sheet (CSS) class rendered by the Web server control on the client.

(Inherited from Style)
DesignMode DesignMode DesignMode DesignMode

Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
Font Font Font Font

Gets the font properties associated with the Web server control.

(Inherited from Style)
ForeColor ForeColor ForeColor ForeColor

Gets or sets the foreground color (typically the color of the text) of the Web server control.

(Inherited from Style)
Height Height Height Height

Gets or sets the height of the Web server control.

(Inherited from Style)
HorizontalAlign HorizontalAlign HorizontalAlign HorizontalAlign

Gets or sets the horizontal alignment of the contents in a cell.

(Inherited from TableItemStyle)
IsEmpty IsEmpty IsEmpty IsEmpty

A protected property. Gets a value indicating whether any style elements have been defined in the state bag.

(Inherited from Style)
IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState IStateManager.IsTrackingViewState

Gets a value that indicates whether a server control is tracking its view state changes.

(Inherited from Style)
IsTrackingViewState IsTrackingViewState IsTrackingViewState IsTrackingViewState

Returns a value indicating whether any style elements have been defined in the state bag.

(Inherited from Style)
Mode Mode Mode 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 NextPageText NextPageText NextPageText

Gets or sets the text displayed for the next page button.

PageButtonCount PageButtonCount PageButtonCount PageButtonCount

Gets or sets the number of numeric buttons to display concurrently in the pager element of the DataGrid control.

Position Position Position Position

Gets or sets the position of the pager element in the DataGrid control.

PrevPageText PrevPageText PrevPageText PrevPageText

Gets or sets the text displayed for the previous page button.

RegisteredCssClass RegisteredCssClass RegisteredCssClass RegisteredCssClass

Gets the cascading style sheet (CSS) class that is registered with the control.

(Inherited from Style)
Site Site Site Site

Gets or sets the ISite of the Component.

(Inherited from Component)
VerticalAlign VerticalAlign VerticalAlign VerticalAlign

Gets or sets the vertical alignment of the contents in a cell.

(Inherited from TableItemStyle)
ViewState ViewState ViewState ViewState

Gets the state bag that holds the style elements.

(Inherited from Style)
Visible Visible Visible Visible

Gets or sets a value indicating whether the pager is displayed in the DataGrid control.

Width Width Width Width

Gets or sets the width of the Web server control.

(Inherited from Style)
Wrap Wrap Wrap Wrap

Gets or sets a value indicating whether the contents of a cell wrap in the cell.

(Inherited from TableItemStyle)

Methods

AddAttributesToRender(HtmlTextWriter) AddAttributesToRender(HtmlTextWriter) AddAttributesToRender(HtmlTextWriter) AddAttributesToRender(HtmlTextWriter)

Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter. This method is primarily used by control developers.

(Inherited from Style)
AddAttributesToRender(HtmlTextWriter, WebControl) AddAttributesToRender(HtmlTextWriter, WebControl) AddAttributesToRender(HtmlTextWriter, WebControl) AddAttributesToRender(HtmlTextWriter, WebControl)

Adds information about horizontal alignment, vertical alignment, and wrap to the list of attributes to render.

(Inherited from TableItemStyle)
CopyFrom(Style) CopyFrom(Style) CopyFrom(Style) CopyFrom(Style)

Copies the style of the specified Style object into this instance of the DataGridPagerStyle class.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
FillStyleAttributes(CssStyleCollection, IUrlResolutionService) FillStyleAttributes(CssStyleCollection, IUrlResolutionService) FillStyleAttributes(CssStyleCollection, IUrlResolutionService) FillStyleAttributes(CssStyleCollection, IUrlResolutionService)

Adds the specified object's style properties to a CssStyleCollection object.

(Inherited from Style)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetStyleAttributes(IUrlResolutionService) GetStyleAttributes(IUrlResolutionService) GetStyleAttributes(IUrlResolutionService) GetStyleAttributes(IUrlResolutionService)

Retrieves the CssStyleCollection object for the specified IUrlResolutionService-implemented object.

(Inherited from Style)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
LoadViewState(Object) LoadViewState(Object) LoadViewState(Object) LoadViewState(Object)

Loads the previously saved state.

(Inherited from Style)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
MergeWith(Style) MergeWith(Style) MergeWith(Style) MergeWith(Style)

Merges the style of the specified Style object with this instance of the DataGridPagerStyle class.

Reset() Reset() Reset() Reset()

Restores the DataGridPagerStyle object to its default values.

SaveViewState() SaveViewState() SaveViewState() SaveViewState()

A protected method. Saves any state that has been modified after the TrackViewState() method was invoked.

(Inherited from Style)
SetBit(Int32) SetBit(Int32) SetBit(Int32) SetBit(Int32)

A protected internal method. Sets an internal bitmask field that indicates the style properties that are stored in the state bag.

(Inherited from Style)
SetDirty() SetDirty() SetDirty() SetDirty()

Marks the Style so that its state will be recorded in view state.

(Inherited from Style)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Style)
TrackViewState() TrackViewState() TrackViewState() 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.

(Inherited from Style)

Events

Disposed Disposed Disposed Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

Explicit Interface Implementations

IStateManager.LoadViewState(Object) IStateManager.LoadViewState(Object) IStateManager.LoadViewState(Object) IStateManager.LoadViewState(Object)

Loads the previously saved state.

(Inherited from Style)
IStateManager.SaveViewState() IStateManager.SaveViewState() IStateManager.SaveViewState() IStateManager.SaveViewState()

Returns the object containing state changes.

(Inherited from Style)
IStateManager.TrackViewState() IStateManager.TrackViewState() IStateManager.TrackViewState() IStateManager.TrackViewState()

Starts tracking state changes.

(Inherited from Style)

Applies to

See also