DataGridPagerStyle Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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 |
Gets or sets the background color of the Web server control. (Inherited from Style) |
BorderColor |
Gets or sets the border color of the Web server control. (Inherited from Style) |
BorderStyle |
Gets or sets the border style of the Web server control. (Inherited from Style) |
BorderWidth |
Gets or sets the border width of the Web server control. (Inherited from Style) |
CanRaiseEvents |
Gets a value indicating whether the component can raise an event. (Inherited from Component) |
Container |
Gets the IContainer that contains the Component. (Inherited from Component) |
CssClass |
Gets or sets the cascading style sheet (CSS) class rendered by the Web server control on the client. (Inherited from Style) |
DesignMode |
Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component) |
Events |
Gets the list of event handlers that are attached to this Component. (Inherited from Component) |
Font |
Gets the font properties associated with the Web server control. (Inherited from Style) |
ForeColor |
Gets or sets the foreground color (typically the color of the text) of the Web server control. (Inherited from Style) |
Height |
Gets or sets the height of the Web server control. (Inherited from Style) |
HorizontalAlign |
Gets or sets the horizontal alignment of the contents in a cell. (Inherited from TableItemStyle) |
IsEmpty |
A protected property. Gets a value indicating whether any style elements have been defined in the state bag. (Inherited from Style) |
IsTrackingViewState |
Returns a value indicating whether any style elements have been defined in the state bag. (Inherited from 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 |
Gets or sets the number of numeric buttons to display concurrently in the pager element of the DataGrid control. |
Position |
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 |
Gets the cascading style sheet (CSS) class that is registered with the control. (Inherited from Style) |
Site |
Gets or sets the ISite of the Component. (Inherited from Component) |
VerticalAlign |
Gets or sets the vertical alignment of the contents in a cell. (Inherited from TableItemStyle) |
ViewState |
Gets the state bag that holds the style elements. (Inherited from Style) |
Visible |
Gets or sets a value indicating whether the pager is displayed in the DataGrid control. |
Width |
Gets or sets the width of the Web server control. (Inherited from Style) |
Wrap |
Gets or sets a value indicating whether the contents of a cell wrap in the cell. (Inherited from TableItemStyle) |
Methods
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) |
Adds information about horizontal alignment, vertical alignment, and wrap to the list of attributes to render. (Inherited from TableItemStyle) |
CopyFrom(Style) |
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. (Inherited from MarshalByRefObject) |
Dispose() |
Releases all resources used by the Component. (Inherited from Component) |
Dispose(Boolean) |
Releases the unmanaged resources used by the Component and optionally releases the managed resources. (Inherited from Component) |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
FillStyleAttributes(CssStyleCollection, IUrlResolutionService) |
Adds the specified object's style properties to a CssStyleCollection object. (Inherited from Style) |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetLifetimeService() |
Obsolete.
Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
GetService(Type) |
Returns an object that represents a service provided by the Component or by its Container. (Inherited from Component) |
GetStyleAttributes(IUrlResolutionService) |
Retrieves the CssStyleCollection object for the specified IUrlResolutionService-implemented object. (Inherited from Style) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
InitializeLifetimeService() |
Obsolete.
Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
LoadViewState(Object) |
Loads the previously saved state. (Inherited from Style) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
MemberwiseClone(Boolean) |
Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject) |
MergeWith(Style) |
Merges the style of the specified Style object with this instance of the DataGridPagerStyle class. |
Reset() |
Restores the DataGridPagerStyle object to its default values. |
SaveViewState() |
A protected method. Saves any state that has been modified after the TrackViewState() method was invoked. (Inherited from Style) |
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() |
Marks the Style so that its state will be recorded in view state. (Inherited from Style) |
ToString() |
Returns a string that represents the current object. (Inherited from 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. (Inherited from Style) |
Events
Disposed |
Occurs when the component is disposed by a call to the Dispose() method. (Inherited from Component) |
Explicit Interface Implementations
IStateManager.IsTrackingViewState |
Gets a value that indicates whether a server control is tracking its view state changes. (Inherited from Style) |
IStateManager.LoadViewState(Object) |
Loads the previously saved state. (Inherited from Style) |
IStateManager.SaveViewState() |
Returns the object containing state changes. (Inherited from Style) |
IStateManager.TrackViewState() |
Starts tracking state changes. (Inherited from Style) |