Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a pager control that I created to drop into the PagerTemplate of a GridView. It's not the most complicated stuff, but it shows how a pager control can 'see' the grid that it belongs to and render a dropdown to jump to a specific page.</p> <p>DataPager.ascx</p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" EnableViewState="true" CodeFile="DataPager.ascx.cs" Inherits="Resources_Controls_DataPager" %&gt; &lt;div&gt; &lt;div style="float:right;"&gt; &lt;asp:ImageButton id="PageFirst" CommandName="Page" CommandArgument="First" runat="server" /&gt; &lt;asp:ImageButton id="PagePrev" CommandName="Page" CommandArgument="Prev" runat="server" /&gt; &amp;nbsp;&amp;nbsp;Page &lt;asp:DropDownList id="pagesDropDown" autopostback="true" OnSelectedIndexChanged="pagesDropDown_SelectedIndexChanged" runat="server" /&gt; &lt;asp:Label id="pageTotalPages" runat="server" /&gt;&amp;nbsp;&amp;nbsp; &lt;asp:ImageButton ID="PageNext" CommandName="Page" CommandArgument="Next" runat="server" /&gt; &lt;asp:ImageButton ID="PageLast" CommandName="Page" CommandArgument="Last" runat="server" /&gt; &lt;/div&gt; &lt;div style="clear:both;"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>DataPager.ascx.cs</p> <pre><code>public partial class Resources_Controls_DataPager : System.Web.UI.UserControl { #region Property: ParentGrid public GridView ParentGrid { get { return (GridView)Parent.Parent.Parent.Parent; } } #endregion protected void Page_Load(object sender, EventArgs e) { FillPage(); } public void FillPage() { if (ParentGrid != null &amp;&amp; pagesDropDown.Items.Count == 0) { pagesDropDown.Items.Clear(); for (int ix = 0; ix &lt; ParentGrid.PageCount; ix++) { ListItem item = new ListItem((ix + 1).ToString()); item.Selected = (ix == ParentGrid.PageIndex); pagesDropDown.Items.Add(item); } if (pagesDropDown.Items.Count == 0) pagesDropDown.Items.Add(new ListItem("0")); pageTotalPages.Text = String.Format("of {0}", ParentGrid.PageCount); } } protected void pagesDropDown_SelectedIndexChanged(object sender, EventArgs e) { ParentGrid.PageIndex = pagesDropDown.SelectedIndex; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload