日期:2014-05-18  浏览次数:20423 次

在gridview外部实现分页
以下为代码:
<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实现"下一页","上一页","跳转到第几页","共多少页","当前为第几页",请问怎样解决,有源码者高分送出,谢谢

------解决方案--------------------
C# code
 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;
                    }