前台:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Pager.ascx.cs" Inherits="e_booking_English_UserControls_Pager" %>
<div style="text-align: right; padding-right: 30px">
    每页<asp:Label ID="pagesize" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageSize %>'
        Style="padding-right: 3px; padding-left: 3px"></asp:Label>项 共<asp:Label ID="rowscount"
            runat="server" Text='<%# ((GridView)Container.Parent.Parent).Rows.Count %>' Style="padding-right: 3px;
            padding-left: 3px"></asp:Label>项
    <asp:LinkButton ID="cmdFirstPage" runat="server" CommandName="Page" CommandArgument="First"
        Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">首页</asp:LinkButton>
    <asp:LinkButton ID="cmdPreview" runat="server" CommandArgument="Prev" CommandName="Page"
        Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">前页</asp:LinkButton>
    第<asp:Label ID="lblcurPage" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex+1%>'
        Style="padding-right: 3px; padding-left: 3px"></asp:Label>页/共<asp:Label ID="lblPageCount"
            runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>' Style="padding-right: 3px;
            padding-left: 3px"></asp:Label>页
    <asp:LinkButton ID="cmdNext" runat="server" CommandName="Page" CommandArgument="Next"
        Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">后页</asp:LinkButton>
    <asp:LinkButton ID="cmdLastPage" runat="server" CommandArgument="Last" CommandName="Page"
        Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">尾页</asp:LinkButton>
    转到<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" CausesValidation="false"
        OnSelectedIndexChanged="DropPageChanged" OnDataBinding="DropDownList1_DataBinding">
    </asp:DropDownList>
    页
</div>

后台:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class e_booking_English_UserControls_Pager : System.Web.UI.UserControl
{
    public GridView grd
    {
        get
        {
            GridView grd = Parent.Parent.NamingContainer as GridView;
            return grd;
        }
    }
    private void Page_Load(object sender, System.EventArgs e)
    {

    }
    protected void DropPageChanged(object sender, EventArgs e)
    {
        DropDownList DropDownList1 = sender as DropDownList;
        grd.PageIndex = int.Parse(DropDownList1.SelectedValue);
    }
    protected void DropDownList1_DataBinding(object sender, EventArgs e)
    {
        for (int i = 1; i <= grd.PageCount; i++)
        {
            DropDownList1.Items.Add(new ListItem(i + "/" + grd.PageCount, (i - 1).ToString()));
        }
        DropDownList1.SelectedIndex = grd.PageIndex;
    }
}

相关文章: