http://dotnet.aspx.cc/ShowDetail.aspx?id=B12283DE-DB20-4322-ACCC-12724442808A

解决方案 »

  1.   

    在datagrid中用数字分页,再加上几个linkbutton
    在linkbutton的onclick事件中加上以下代码:
    Dim arg As String = CType(sender, LinkButton).CommandArgument
            Select Case arg
                Case ("next")
                    If (DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1)) Then
                        DataGrid1.CurrentPageIndex += 1
                    End If
                Case ("prev")
                    If (DataGrid1.CurrentPageIndex > 0) Then
                        DataGrid1.CurrentPageIndex -= 1
                    End If
                Case ("last")
                    DataGrid1.CurrentPageIndex = (DataGrid1.PageCount - 1)
                Case ("NumPage")
                    DataGrid1.CurrentPageIndex = IIf(CInt(PageN.Text) >     DataGrid1.PageCount Or CInt(PageN.Text) < 1, 0, CInt(PageN.Text) - 1)
                Case Else
                    '本页值
                    DataGrid1.CurrentPageIndex = CInt(arg)
            End Select
     BindGrid()
      

  2.   

    看了求知给的地址,觉得里面老大介绍的方法不是很好.我也贴一个.比比看.
    我这里的函数,直接使用就好.
    /// <summary>
    /// 返回用于分页的HTML文本
    /// </summary>
    /// <param name="recordCount">记录总条数</param>
    /// <param name="pageSize">每页大小</param>
    /// <param name="currPage">当前页</param>
    /// <returns>返回HTML文本</returns>
    public static string GetPaperHtml(int recordCount,int pageSize,int currPage)
    {
    System.Text.StringBuilder result=new System.Text.StringBuilder("");
    int pageOfBlock=10; //每块可以放几页
    int maxPage=(recordCount+pageSize-1)/pageSize; //一共分多少页
    int maxBlock=(maxPage+pageOfBlock-1)/pageOfBlock; //共有多少块
    int currBlock=(currPage+pageOfBlock-1)/pageOfBlock; //当前是第几块
    int nextPage=currPage+1; //下一页的页数
    int previousPage=currPage-1; //前一页的页数
    int nextBlockFirst=currBlock*pageOfBlock+1; //下一块的第一页
    int previousBlockLast=(currBlock-1)*pageOfBlock; //上一块的第一页
    //如果是第一页,则上一页和最前一页的链接无效
    if (currPage>1)
    {
    string href="SIndex.aspx?TextSearch=\"+escape('"+TextSearch+"')+\"&DropSearch="+ASearch+"&page=1";
    result.Append("<a title='首页' href='"+href+"'><font face='webdings'>9</font></a>&nbsp;&nbsp;");
    href="SIndex.aspx?TextSearch=\"+escape('"+TextSearch+"')+\"&DropSearch="+ASearch+"&page="+(--pageIndex);
    result.Append("<a title='上一页' href='"+href+"'><font face='webdings'>3</font></a>&nbsp;&nbsp;");
    }
    else
    {
    result.Append("<a disabled='true'><font face='webdings'>9</font></a>&nbsp;&nbsp;");
    result.Append("<a disabled='true'><font face='webdings'>3</font></a>&nbsp;&nbsp;");
    }
    //如果是不是一块,则加上一个返回上一块的链接
    if (currBlock>1)
    {
    string href="SIndex.aspx?TextSearch=\"+escape('"+TextSearch+"')+\"&DropSearch="+ASearch+"&page="+previousBlockLast.ToString();
    result.Append("<a title='前十页' href='"+href+"'>...</a>&nbsp;");
    }
    //循环每一页
    if (maxPage!=0)
    {
    //如果下一块的第一页大于最大页,则这一块的结束页索引为最大页,否则为下一块的第一页减1.
    int endPage = (nextBlockFirst > maxPage) ? maxPage : nextBlockFirst - 1;
    for (int i=previousBlockLast+1;i<=endPage;i++)
    {
    if (i==currPage)
    {
    result.Append("<font color='Red'>-<b>" + i.ToString() + "</b>-</font>&nbsp;");
    }
    else
    {
    string href="SIndex.aspx?TextSearch=\"+escape('"+TextSearch+"')+\"&DropSearch="+ASearch+"&page="+i.ToString();
    result.Append("<a title='第" + i.ToString() +"页' href='"+href+"'>[&nbsp;" + i.ToString() + "&nbsp;]</a>&nbsp;");
    }
    }
    }
    //如果不是最后一块,则加上一个指向下一块的链接
    if (currBlock<maxBlock)
    {
    string href="SIndex.aspx?TextSearch=\"+escape('"+TextSearch+"')+\"&DropSearch="+ASearch+"&page="+nextBlockFirst.ToString();
    result.Append("<a title='后十页' href='"+href+"'>...</a>&nbsp;&nbsp;");
    }
    //如果是最后一页或者记录数为零,则下一页及最后一页的链接无效
    if (currPage!=maxPage && recordCount!=0)
    {
    pageIndex++;
    string href="SIndex.aspx?TextSearch=\"+escape('"+TextSearch+"')+\"&DropSearch="+ASearch+"&page="+(pageIndex);
    result.Append("<a title='下一页' href='"+href+"'><font face='webdings'>4</font></a>&nbsp;&nbsp;");
    int count=0;
    if(int.Parse(PLDs.Tables[0].Rows[0][7].ToString())%10==0)
    {
    count=int.Parse(PLDs.Tables[0].Rows[0][7].ToString())/10;
    }
    else
    {
    count=int.Parse(PLDs.Tables[0].Rows[0][7].ToString())/10+1;
    }
    pageIndex=count;
    href="SIndex.aspx?TextSearch=\"+escape('"+TextSearch+"')+\"&DropSearch="+ASearch+"&page="+(pageIndex);
    result.Append("<a title='末页' href='"+href+"'><font face='webdings'>:</font></a>&nbsp;&nbsp;");
    }
    else
    {
    result.Append("<a disabled='true'><font face='webdings'>4</font></a>&nbsp;&nbsp;");
    result.Append("<a disabled='true'><font face='webdings'>:</font></a>&nbsp;&nbsp;&nbsp;");
    }
    return result.ToString();
    }
      

  3.   

    用这个方法.可以减少很多数据流量.不过datagrid连数据库的时候就要掉存储过程了.代码虽然比上面大哥多一点。但速度不是一个等级的.不信你试试...存储过程大概是只返回特定N行.并返回是第几页~
      

  4.   

    看看webdiyer的分页控件,http://webdiyer.europe.webmatrixhosting.net/