以下为代码:
<TR>
<TD> <asp:GridView ID="GridView1" runat="server" CssClass="GridViewStyle" GridLines="None">
            <FooterStyle CssClass="GridViewFooterStyle" />
            <RowStyle CssClass="GridViewRowStyle" />
            <PagerStyle CssClass="GridViewPagerStyle" />
            <SelectedRowStyle CssClass="GridViewSelectedRowStyle" />
            <HeaderStyle CssClass="GridViewHeaderStyle" />
            <EditRowStyle CssClass="GridViewEditRowStyle" />
            <AlternatingRowStyle CssClass="GridViewAlternatingRowStyle" />
        </asp:GridView>
</TR>
</TD> 
<TR>
<TD>
<asp:ImageButton ID="IMLastPage" runat="server" ImageUrl="~/EIPOA/images/last02.gif" />最后一页</td>
跳转到<textboxt></text>页....其他类似
<TD>
<TR>
然后我不想在GridView内部使用分页,需要在外部用imagebutton实现"下一页","上一页","跳转到第几页","共多少页","当前为第几页",请问怎样解决,有源码者高分送出,谢谢

解决方案 »

  1.   

     private static string ConStr = ConfigurationManager.ConnectionStrings["ConnectionNorthwind"].ConnectionString;
        double _totalPages;
        Int32 _currentPageNumber = 1;
        //以下两种的存储过程数据表中的数据都是万级别的,各种方法的效率差别不是很大
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindDataReturn(_currentPageNumber);
               // BindData(_currentPageNumber);        }
        }    //调用采用临时表分页的存储过程
        private void BindData(int pageIndex)
        {
            using (SqlConnection Con = new SqlConnection(ConStr))
            {
                using (SqlCommand Cmd = new SqlCommand("Get_Customers_By_Page", Con))
                {
                    Cmd.CommandType = CommandType.StoredProcedure;
                    Cmd.Parameters.AddWithValue("@CurrentPage", pageIndex);
                    Cmd.Parameters.AddWithValue("@PageSize", gvCustomer.PageSize);
                    SqlParameter ParmTotal = new SqlParameter("@TotalRecords", SqlDbType.Int);
                    //获取存储过程中的输出参数
                    ParmTotal.Direction = ParameterDirection.Output;
                    Cmd.Parameters.Add(ParmTotal);
                    //Cmd.Parameters.Add(new SqlParameter("@TotalRecords",SqlDbType.Int)).Direction = ParameterDirection.Output;
                    Con.Open();
                    gvCustomer.DataSource = Cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    gvCustomer.DataBind();                CurrentPage.Text = _currentPageNumber.ToString();
                    if (!Page.IsPostBack)
                    {
                        //必须关闭DR才能正确的获取输出参数的值
                        int Total = ((Int32)Cmd.Parameters["@TotalRecords"].Value);
                        _totalPages = Total / ((int)gvCustomer.PageSize);
                        TotalPages.Text = (System.Math.Ceiling(_totalPages)).ToString();
                    }
                    if (_currentPageNumber == 1)
                    {
                        PreviousPage.Enabled = false;                    if (_totalPages > 1)
                        {
                            NextPage.Enabled = true;
                        }
                        else
                        {
                            NextPage.Enabled = false;
                        }
                    }
                    else
                    {
                        PreviousPage.Enabled = true;                    if (_currentPageNumber == _totalPages)
                        {
                            NextPage.Enabled = false;
                        }
                        else
                        {
                            NextPage.Enabled = true;
                        }
                    }            }
            }
        }
        //调用采用select top分页存储过程
        private void BindDataReturn(Int32 pageIndex)
        {
            using (SqlConnection Con = new SqlConnection(ConStr))
            {
                using (SqlCommand Cmd = new SqlCommand("PagingSelectTop", Con))
                {
                    Cmd.CommandType = CommandType.StoredProcedure;
                    Cmd.Parameters.AddWithValue("@PageCount", pageIndex);
                    Cmd.Parameters.AddWithValue("@RowCount", gvCustomer.PageSize);
                    SqlParameter ParmRowCount = new SqlParameter("@TotalRecord",SqlDbType.Int);
                    //获取存储过程中的返回值
                    ParmRowCount.Direction = ParameterDirection.ReturnValue;
                    Cmd.Parameters.Add(ParmRowCount);
                    Con.Open();
                    using (SqlDataReader Dr = Cmd.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        gvCustomer.DataSource = Dr;
                        gvCustomer.DataBind();
                        CurrentPage.Text = _currentPageNumber.ToString();
                    }
                    int Total;
                    if (!Page.IsPostBack)
                    {
                        Total = (Int32)Cmd.Parameters["@TotalRecord"].Value;
                        _totalPages = Total / ((int)gvCustomer.PageSize);
                        TotalPages.Text = (System.Math.Ceiling(_totalPages)).ToString();
                    }
                }
            }
        }    //分页导航
        protected void NavigationLink_Click(Object sender, CommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "First":
                    _currentPageNumber = 1;
                    break;
                case "Last":
                    _currentPageNumber = Int32.Parse(TotalPages.Text);
                    break;
                case "Next":
                    _currentPageNumber = (int)(Int32.Parse(CurrentPage.Text) + 1);
                    break;
                case "Prev":
                    _currentPageNumber = Int32.Parse(CurrentPage.Text) - 1;
                    break;
            }        //BindData(_currentPageNumber);
            BindDataReturn(_currentPageNumber);
        }
    <head runat="server">
        <title>Untitled Page</title>
        <style type="text/css">
            .tableItem
            {
                font: x-small Verdana, Arial, sans-serif;
            }
            .tableHeader
            {
                font: bold small Arial;
                color: #663300;
                background-color: #CCCC66;
            }
            .alternatingItem
            {
                font: x-small Verdana, Arial, sans-serif;
                background-color: #FFFFCC;
            }
            A
            {
                color: #663300;
            }
            A:hover
            {
                color: red;
            }
            .pageLinks
            {
                font: bold x-small Verdana, Arial, sans-serif;
            }
            .position
            {
                margin-left: 330px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div class="position">
            <asp:GridView ID="gvCustomer" runat="server" BackColor="#CCCCCC" BorderColor="#999999"
                BorderStyle="Solid" BorderWidth="3px" CellPadding="4" PageSize="16" CellSpacing="2"
                ForeColor="Black">
                <FooterStyle BackColor="#CCCCCC" />
                <RowStyle BackColor="White" />
                <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                <%--<PagerTemplate>
                    <asp:Button ID="btnFirst" runat="server" CommandName="First" Text="First" />
                    <asp:Button ID="btnPre" runat="server" CommandName="Prev" Text="<<" />
                    <asp:Button ID="btnNext" runat="server" CommandName="Next" Text=">>" />
                    <asp:Button ID="btnLast" runat="server" CommandName="Last" Text="Last" />
                </PagerTemplate>--%>
            </asp:GridView>
        </div>
        <center>
            <p class="pageLinks">
                <b>Page
                    <asp:Label ID="CurrentPage" CssClass="pageLinks" runat="server" />
                    of
                    <asp:Label ID="TotalPages" CssClass="pageLinks" runat="server" />
            </p>
            <asp:LinkButton runat="server" CssClass="pageLinks" ID="FirstPage" Text="[First Page]"
                OnCommand="NavigationLink_Click" CommandName="First" />
            <asp:LinkButton runat="server" CssClass="pageLinks" ID="PreviousPage" Text="[Previous Page]"
                OnCommand="NavigationLink_Click" CommandName="Prev" />
            <asp:LinkButton runat="server" CssClass="pageLinks" ID="NextPage" Text="[Next Page]"
                OnCommand="NavigationLink_Click" CommandName="Next" />
            <asp:LinkButton runat="server" CssClass="pageLinks" ID="LastPage" Text="[Last Page]"
                OnCommand="NavigationLink_Click" CommandName="Last" />
        </center>
        </form>
    </body>
      

  2.   

    我刚写了个分页控件 正符合你的要求 只两百多行代码 有说明和下载  
    http://blog.csdn.net/WO_YOU_XIE_SHANG_XIN/archive/2008/05/05/2393801.aspx
      

  3.   


    哦这点不满足 我用的LinkButton