有什么不好的地方欢迎指点,主要运用sql2005的ROW_NUMBER()
分页其实很简单,只要把页参数传递到以下SQL语句中即可。
where number between cast('" & PageSize & "' as int) *(cast('" & CurrentPage & "' as int)-1)+1 and cast('" & PageSize & "' as int)*cast('" & CurrentPage & "' as int)")
如果不懂vb.net可以到这个网页把代码转换为c#  http://www.developerfusion.com/tools/convert/vb-to-csharp/
前台用 gridview repeater datalist 都是一样的。
前台
<asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                
                     <ContentTemplate>
<asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table id="tb01" width="260%" border="0" cellspacing="1" cellpadding="2" bgcolor="#dddddd">
<tbody>
<tr style="background-color:#ffffff">
<td class="trTitle"  style="width:80px;background-image:url(images/trbg02.gif);background-color:#ffffff;height:23px;" >編號</td>
<td class="trTitle"  style="width:80px;background-image:url(images/trbg02.gif);background-color:#ffffff;height:23px;">姓名</td>
<td class="trTitle"   style="width:150px;background-image:url(images/trbg02.gif);background-color:#ffffff;height:23px;">名稱</td>

</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#ffffff">
<td height="20px"  align="left">
<a style="cursor:hand" href="<%= strLinkManitCrsCat %>&recid=<%# Container.DataItem("rec_id") %>&mode=1"  title="編輯/刪除"><strong><asp:label  Font-Names="Tahoma" id="lblClassNum" Width="80px" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"emp_id") %>'>
</asp:label></strong></a>
</td>
<td align="left">
<asp:label id="Label4" Width="80px" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"emp_chn_nam") %>'>
</asp:label>
</td>
<td align="left">
<asp:label id="lblCrsCatDesc" Width="150px" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"crs_num") %>'>
</asp:label>
</td>

</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr bgcolor="#f9f9f9">
<td height="20px"  align="left">
<a style="cursor:hand" href="<%= strLinkManitCrsCat %>&recid=<%# Container.DataItem("rec_id") %>&mode=1" title="編輯/刪除"><strong><asp:label Font-Names="Tahoma" id="lblClassNum" Width="80px" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"emp_id") %>'>
</asp:label></strong></a>
</td>
<td align="left">
<asp:label id="Label4" Width="80px" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"emp_chn_nam") %>'>
</asp:label>
</td>
<td align="left">
<asp:label id="lblCrsCatDesc" Width="150px" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"crs_num") %>'>
</asp:label>
</td>
<td align="left">
<asp:label id="Label8" Width="60px" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"cls_num") %>'>
</asp:label>
</td>



</tr>
</AlternatingItemTemplate>
<FooterTemplate>
<tr bgcolor="#f2f2f2">
<td height="8" colspan="22" align="center"></td>
</tr>
</tbody></table>
</FooterTemplate>
</asp:repeater>
<div style="PADDING-TOP:10px" align="center">
                
&nbsp; 共<asp:label id="LPageCount" ForeColor="#ff0000" Runat="server"></asp:label>頁
<asp:label id="LTotalCount" ForeColor="#ff0000" Runat="server"></asp:label>條記錄
<asp:linkbutton id="Fistpage" Runat="server" CommandName="0">首頁</asp:linkbutton>
<asp:linkbutton id="Prevpage" Runat="server" CommandName="prev">上一頁</asp:linkbutton>
<asp:linkbutton id="Nextpage" Runat="server" CommandName="next">下一頁</asp:linkbutton>
<asp:linkbutton id="Lastpage" Runat="server" CommandName="last">尾頁</asp:linkbutton>當前第
<asp:label id="LCurrentPage" ForeColor="#ff0000" Runat="server"></asp:label>頁
           &nbsp; 轉到第
           <asp:textbox id="gotoPage" Width="30px" Runat="server" AutoPostBack="True" MaxLength="5" ></asp:textbox>頁
           <asp:Label style=" POSITION: absolute" id="msgbox" runat="server" ForeColor="Red" BorderColor="Red"></asp:Label>
           </div>
           
           </ContentTemplate>                
</asp:UpdatePanel>
<input type="hidden" id="sortfield" runat="server" name="sortfield"/> <input type="hidden" id="sortstring" runat="server" name="sortstring"/>&nbsp;
</form>
</body>
</html>

解决方案 »

  1.   


    Imports System.DataPartial Class TrainRecNavigation
        Inherits System.Web.UI.Page
        Public strLinkManitCrsCat As String
        Public strlinkQueryCrsCat As String
        Public strlink2 As String
        Public strClassNum As String = ""
        Public strCourseNum As String = ""
        Dim strfac As String = ""
        Dim strdept As String = ""
        Dim strApproDate As String = ""
        Dim strApproDate2 As String = ""
        Dim strApproStatus As String = ""
        Dim strTutorID As String = ""
        Dim strpage As String = ""
        Dim coursenum As Integer, classnum As Integer
        Dim PageCount As Integer, RecCount As Integer, CurrentPage As Integer, Current As Integer, Pages As Integer, JumpPage As Integer
        Dim PageSize As Integer = 15
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Session("UserID") = "" Then
                Response.Write("<script>alert('您尚未登錄或登錄超時,請重新登錄!');parent.location.href='login.aspx';</script>>")
            End If
            strClassNum = Server.UrlDecode(Request.QueryString("strClassNum")) & ""
            strCourseNum = Server.UrlDecode(Request.QueryString("strCourseNum")) & ""
            strfac = Server.UrlDecode(Request.QueryString("strfac")) & ""
            strdept = Server.UrlDecode(Request.QueryString("strdept")) & ""
            strApproDate = Server.UrlDecode(Request.QueryString("strApproDate")) & ""
            strApproDate2 = Server.UrlDecode(Request.QueryString("strApproDate2")) & ""
            strApproStatus = Server.UrlDecode(Request.QueryString("strApproStatus")) & ""
            strTutorID = Server.UrlDecode(Request.QueryString("strTutorID")) & ""
            strpage = Request.QueryString("page") & ""
            If Not Page.IsPostBack Then
                '-----------------------------------------
                RecCount = Calc()
                '計算總記錄
                PageCount = RecCount / PageSize + OverPage()
                '計算總頁數
                ViewState("PageCounts") = RecCount / PageSize - ModPage()
                If strpage <> "" Then
                    '設置當前頁為返回頁
                    ViewState("PageIndex") = CInt(strpage)
                Else
                    '設置當前頁為1
                    ViewState("PageIndex") = 1
                    Session("CurPage") = 1
                End If            ViewState("JumpPages") = PageCount
                LPageCount.Text = PageCount.ToString()
                LTotalCount.Text = RecCount.ToString()            If RecCount <= PageSize Then
                    gotoPage.Enabled = False
                Else
                    gotoPage.Enabled = True
                End If
                'msgbox.Text = RecCount
                '----------------------------------------
                Call CreatePagedDataSource("")
            End If
            strLinkManitCrsCat = GotoMaintPage()
            strlinkQueryCrsCat = GotoQueryPage()
            strlink2 = GotoMaintPage2()
        End Sub
    #Region "計算總行數"
        Public Function OverPage() As Integer
            '算余
            Dim pages As Integer = 0
            If RecCount Mod PageSize <> 0 Then
                pages = 1
            Else
                pages = 0
            End If
            Return pages
        End Function
        Public Function ModPage() As Integer
            '算余
            Dim pages As Integer = 0
            If RecCount Mod PageSize = 0 AndAlso RecCount <> 0 Then
                pages = 1
            Else
                pages = 0
            End If
            Return pages
        End Function
        Public Function Calc() As Integer
            '計算記錄總數 
            Dim clsDBProcess As New dbprocess.OledbProcess
            Dim dsResult As New DataSet
            'Dim a5 As String = Server.UrlDecode(Request.QueryString("a5"))
            Dim ass As New StringBuilder("Select count(cls_num) as co from  TRAIN_REC a  where 1=1 ")
            If strClassNum.Trim.Length > 0 Then
                ass.Append(" And a.cls_num like '%" & strClassNum & "%'")
            End If
            If strCourseNum.Trim.Length > 0 Then
                ass.Append(" And a.crs_num like '%" & strCourseNum & "%'")
            End If
            If strfac.Trim.Length > 0 Then
                ass.Append(" And a.fac_num like '%" & strfac & "%'")
            End If
            If strdept.Trim.Length > 0 Then
                ass.Append(" And a.dept_num like '%" & strdept & "%'")
            End If
            If strApproStatus.Trim.Length > 0 Then
                ass.Append(" And a.appro_status like '%" & strApproStatus & "%'")
            End If
            If strTutorID.Trim.Length > 0 Then
                ass.Append(" And a.emp_id like '%" & strTutorID & "%'")
            End If
            If strApproDate.Trim.Length > 0 And strApproDate2.Trim.Length = 0 Then
                ass.Append(" And a.appro_date like '%" & strApproDate & "%' ")
            End If
            If strApproDate.Trim.Length > 0 And strApproDate2.Trim.Length > 0 Then
                ass.Append(" And a.appro_date between '" & strApproDate & "' and '" & strApproDate2 & "' ")
            End If
            Dim bss As String = ass.ToString()
            Dim RecordCount As Integer = 0        dsResult = clsDBProcess.GetDataSet(Session("Server"), Session("Database"), bss)
            RecordCount = Int32.Parse(dsResult.Tables(0).Rows(0)(0))
            Return RecordCount
            msgbox.Text = RecordCount
        End Function
    #End Region
    #Region "翻頁"
        '下一頁
        Protected Sub Nextpage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Nextpage.Click
            CurrentPage = CInt(ViewState("PageIndex"))
            Pages = CInt(ViewState("PageCounts"))
            CurrentPage = CurrentPage + 1
            ViewState("PageIndex") = CurrentPage
            Session("CurPage") = CurrentPage
            CreatePagedDataSource("")
        End Sub
        '上一頁
        Protected Sub Prevpage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Prevpage.Click
            CurrentPage = CInt(ViewState("PageIndex"))
            Pages = CInt(ViewState("PageCounts"))
            CurrentPage -= 1
            ViewState("PageIndex") = CurrentPage
            Session("CurPage") = CurrentPage
            CreatePagedDataSource("")
        End Sub
        '最后一頁
        Protected Sub Lastpage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Lastpage.Click
            CurrentPage = CInt(ViewState("PageIndex"))
            Pages = CInt(ViewState("PageCounts"))
            CurrentPage = Pages
            ViewState("PageIndex") = CurrentPage
            Session("CurPage") = CurrentPage
            CreatePagedDataSource("")
        End Sub
        '第一頁
        Protected Sub Fistpage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Fistpage.Click
            CurrentPage = CInt(ViewState("PageIndex"))
            Pages = CInt(ViewState("PageCounts"))
            CurrentPage = 1
            ViewState("PageIndex") = CurrentPage
            Session("CurPage") = CurrentPage
            CreatePagedDataSource("")
        End Sub
        
        '轉到第幾頁
        Protected Sub gotoPage_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gotoPage.TextChanged
            Dim asd As String = Me.gotoPage.Text.Trim().ToString()
            JumpPage = CInt(ViewState("JumpPages"))
            If asd = "" Then
                Alert("超出范围")
                Return
            End If
            If Int32.Parse(gotoPage.Text) > JumpPage OrElse Int32.Parse(gotoPage.Text) <= 0 OrElse asd = "" Then
                Alert("超出范围")
                Return
            Else
                Dim InputPage As Integer = Int32.Parse(gotoPage.Text.ToString())
                ViewState("PageIndex") = InputPage
                Session("CurPage") = InputPage
                CreatePagedDataSource("")
            End If
        End Sub
    #End Region
        
       
      

  2.   

     
    Public Sub CreatePagedDataSource(ByVal strStringValue As String)
            Dim intPage As Integer, strMid As String
            Dim strSQL As String = ""
            Dim dsResult As New DataSet
            Dim clsDBProcess As New dbprocess.OledbProcess
            Dim strMidName As String
            Dim strGetDataFlag As String        CurrentPage = CInt(ViewState("PageIndex"))
            Pages = CInt(ViewState("PageCounts"))
            If CurrentPage > 1 Then
                Fistpage.Enabled = True
                Prevpage.Enabled = True
            Else
                Fistpage.Enabled = False
                Prevpage.Enabled = False
            End If
            If CurrentPage = Pages + 1 Then
                Nextpage.Enabled = False
                Lastpage.Enabled = False
            Else
                Nextpage.Enabled = True
                Lastpage.Enabled = True
            End If
            Try
                strGetDataFlag = Request.QueryString("getdata") & ""
                strMid = Request.QueryString("mid") & ""
                strMidName = GetMenuName(Session("Server"), Session("Database"), strMid)
                tb1.Rows(0).Cells(0).InnerHtml = "&nbsp;<b>" & strMidName & "</b>"            If strGetDataFlag = "1" Then
                    'rec_id,crs_num,cls_num,emp_id,fac_num,dept_num,grade_id,title_id,atn_status,lev_status,taken_hr,exam_result,finasst_per,finasst_amt,finasst_apr_date,finasst_act_date,re,appro_user_id,appro_date,appro_status,crt_datetime,crt_user,chg_datetime,chg_user
                    'rec_id,crs_num,emp_id,emp_id,fac_num,dept_num,grade_id,title_id,atn_status,lev_status,taken_hr,exam_result,finasst_per,finasst_amt,finasst_apr_date,finasst_act_date,re,appro_user_id,appro_date,appro_status,crt_datetime,crt_user,chg_datetime,chg_user                Dim strSQL2 As New StringBuilder("select * from (select a.rec_id,a.cls_num,a.emp_id,a.taken_hr,a.exam_result,a.finasst_per,a.finasst_amt,a.finasst_apr_date,a.finasst_act_date,a.crt_datetime,a.chg_datetime,CONVERT(varchar(100),a.appro_date, 23) as appro_date,ROW_NUMBER() OVER(ORDER BY a.rec_id) AS number, ")
                    strSQL2.Append("b.dept_nam as dept_num,c.fac_num as fac_num,d.crs_nam as crs_num,e.user_nam as chg_user,f.user_nam as crt_user,g.code_value as grade_id,h.title_nam as title_id,i.code_value as atn_status,j.code_value as appro_status,k.emp_chn_nam,m.cls_start_date,m.cls_end_date,m.cls_start_time,m.cls_end_time,m.center_venue  from TRAIN_REC a ")
                    strSQL2.Append("left join dept b on  a.dept_num=b.dept_num and a.fac_num=b.fac_num left join facility c on a.fac_num=c.fac_num   left join course d on a.crs_num=d.crs_num  left join user_id e on a.chg_user=e.user_id left join user_id f on a.crt_user=f.user_id ")
                    strSQL2.Append(" left join CodeTable g on a.grade_id=g.code_id and g.table_id='Grade' left join title h on a.title_id=h.title_id and h.fac_num=a.fac_num left join CodeTable i on a.atn_status=i.code_id and i.table_id='CrsStatus' ")
                    strSQL2.Append(" left join CodeTable j on a.appro_status=j.code_id and j.table_id='AppStatus' left join employee k on a.emp_id=k.emp_id  ")
                    strSQL2.Append("left join (select r1.cls_num,r1.cls_start_date,r1.cls_end_date,r1.cls_start_time,r1.cls_end_time,r2.center_venue  from classes r1 left join train_center r2 on r1.center_id=r2.center_id ) m on a.cls_num=m.cls_num )T1 where number between cast('" & PageSize & "' as int) *(cast('" & CurrentPage & "' as int)-1)+1 and cast('" & PageSize & "' as int)*cast('" & CurrentPage & "' as int)")
                    If strClassNum.Trim.Length > 0 Then
                        strSQL2.Append(" And a.cls_num like '%" & strClassNum & "%'")
                    End If
                    If strCourseNum.Trim.Length > 0 Then
                        strSQL2.Append(" And a.crs_num like '%" & strCourseNum & "%'")
                    End If
                    If strfac.Trim.Length > 0 Then
                        strSQL2.Append(" And a.fac_num like '%" & strfac & "%'")
                    End If
                    If strdept.Trim.Length > 0 Then
                        strSQL2.Append(" And a.dept_num like '%" & strdept & "%'")
                    End If
                    If strApproStatus.Trim.Length > 0 Then
                        strSQL2.Append(" And a.appro_status like '%" & strApproStatus & "%'")
                    End If
                    If strTutorID.Trim.Length > 0 Then
                        strSQL2.Append(" And a.emp_id like '%" & strTutorID & "%'")
                    End If
                    If strApproDate.Trim.Length > 0 And strApproDate2.Trim.Length = 0 Then
                        strSQL2.Append(" And a.appro_date like '%" & strApproDate & "%' ")
                    End If
                    If strApproDate.Trim.Length > 0 And strApproDate2.Trim.Length > 0 Then
                        strSQL2.Append(" And a.appro_date between '" & strApproDate & "' and '" & strApproDate2 & "' ")
                    End If
                    ' strSQL &= " order by a.cls_num desc"
                    dsResult = clsDBProcess.GetDataSet(Session("Server"), Session("Database"), strSQL2.ToString)
                    Repeater1.DataSource = dsResult
                    Repeater1.DataBind()
                    LCurrentPage.Text = CurrentPage.ToString()
                    'msgbox.Text = Pages.ToString()
                End If
            Catch ex As Exception
                msgbox.Text = (ex.ToString)
            Finally
                dsResult = Nothing
                clsDBProcess = Nothing
            End Try
        End Sub
        
    End Class
      

  3.   

    其实核心的东西就是这一条语句 ,翻页时只要把参数传递进去就行了。SELECT * FROM (
    SELECT ROW_NUMBER() OVER(ORDER BY ProductID ASC) RowNum, * FROM Production.Product ) OrderData
    WHERE RowNum BETWEEN @iRowCount*(@iPageNo-1)+1 and @iRowCount*@iPageNo
      

  4.   

    晕死 看晕了 直接aspnetpager + 存储即可啊
      

  5.   

    spnetPager应该只是个分页查询,没有针对大数据量做优化
      

  6.   

    我来接分   至于分页 哈哈  本人还要sql存储过程
      

  7.   

    ROW_NUMBER()是我目前见过效率最高的分页方法
      

  8.   

    用linq比较方便
    skip().take()
    大法就ok了 从本质上来说  是一样的
      

  9.   

    貼c#的
    using System.Data; partial class TrainRecNavigation : System.Web.UI.Page 

        public string strLinkManitCrsCat; 
        public string strlinkQueryCrsCat; 
        public string strlink2; 
        public string strClassNum = ""; 
        public string strCourseNum = ""; 
        string strfac = ""; 
        string strdept = ""; 
        string strApproDate = ""; 
        string strApproDate2 = ""; 
        string strApproStatus = ""; 
        string strTutorID = ""; 
        string strpage = ""; 
        int coursenum; 
        int classnum; 
        int PageCount; 
        int RecCount; 
        int CurrentPage; 
        int Current; 
        int Pages; 
        int JumpPage; 
        int PageSize = 15; 
        private void // ERROR: Handles clauses are not supported in C# Page_Load(object sender, System.EventArgs e) 
        { 
            if (string.IsNullOrEmpty(Session("UserID"))) { 
                Response.Write("<script>alert('您尚未登錄或登錄超時,請重新登錄!');parent.location.href='login.aspx';</script>>"); 
            } 
            strClassNum = Server.UrlDecode(Request.QueryString("strClassNum")) + ""; 
            strCourseNum = Server.UrlDecode(Request.QueryString("strCourseNum")) + ""; 
            strfac = Server.UrlDecode(Request.QueryString("strfac")) + ""; 
            strdept = Server.UrlDecode(Request.QueryString("strdept")) + ""; 
            strApproDate = Server.UrlDecode(Request.QueryString("strApproDate")) + ""; 
            strApproDate2 = Server.UrlDecode(Request.QueryString("strApproDate2")) + ""; 
            strApproStatus = Server.UrlDecode(Request.QueryString("strApproStatus")) + ""; 
            strTutorID = Server.UrlDecode(Request.QueryString("strTutorID")) + ""; 
            strpage = Request.QueryString("page") + ""; 
            if (!Page.IsPostBack) { 
                //----------------------------------------- 
                RecCount = Calc(); 
                //計算總記錄 
                PageCount = RecCount / PageSize + OverPage(); 
                //計算總頁數 
                ViewState("PageCounts") = RecCount / PageSize - ModPage(); 
                if (!string.IsNullOrEmpty(strpage)) { 
                    //設置當前頁為返回頁 
                    ViewState("PageIndex") = (int)strpage; 
                } 
                else { 
                    //設置當前頁為1 
                    ViewState("PageIndex") = 1; 
                    Session("CurPage") = 1; 
                } 
                
                ViewState("JumpPages") = PageCount; 
                LPageCount.Text = PageCount.ToString(); 
                LTotalCount.Text = RecCount.ToString(); 
                
                if (RecCount <= PageSize) { 
                    gotoPage.Enabled = false; 
                } 
                else { 
                    gotoPage.Enabled = true; 
                } 
                //msgbox.Text = RecCount 
                //---------------------------------------- 
                CreatePagedDataSource(""); 
            } 
            strLinkManitCrsCat = GotoMaintPage(); 
            strlinkQueryCrsCat = GotoQueryPage(); 
            strlink2 = GotoMaintPage2(); 
        } 
        #region "計算總行數" 
        public int OverPage() 
        { 
            //算余 
            int pages = 0; 
            if (RecCount % PageSize != 0) { 
                pages = 1; 
            } 
            else { 
                pages = 0; 
            } 
            return pages; 
        } 
        public int ModPage() 
        { 
            //算余 
            int pages = 0; 
            if (RecCount % PageSize == 0 && RecCount != 0) { 
                pages = 1; 
            } 
            else { 
                pages = 0; 
            } 
            return pages; 
        } 
        public int Calc() 
        { 
            //計算記錄總數 
            dbprocess.OledbProcess clsDBProcess = new dbprocess.OledbProcess(); 
            DataSet dsResult = new DataSet(); 
            //Dim a5 As String = Server.UrlDecode(Request.QueryString("a5")) 
            StringBuilder ass = new StringBuilder("Select count(cls_num) as co from TRAIN_REC a where 1=1 "); 
            if (strClassNum.Trim.Length > 0) { 
                ass.Append(" And a.cls_num like '%" + strClassNum + "%'"); 
            } 
            if (strCourseNum.Trim.Length > 0) { 
                ass.Append(" And a.crs_num like '%" + strCourseNum + "%'"); 
            } 
            if (strfac.Trim.Length > 0) { 
                ass.Append(" And a.fac_num like '%" + strfac + "%'"); 
            } 
            if (strdept.Trim.Length > 0) { 
                ass.Append(" And a.dept_num like '%" + strdept + "%'"); 
            } 
            if (strApproStatus.Trim.Length > 0) { 
                ass.Append(" And a.appro_status like '%" + strApproStatus + "%'"); 
            } 
            if (strTutorID.Trim.Length > 0) { 
                ass.Append(" And a.emp_id like '%" + strTutorID + "%'"); 
            } 
            if (strApproDate.Trim.Length > 0 & strApproDate2.Trim.Length == 0) { 
                ass.Append(" And a.appro_date like '%" + strApproDate + "%' "); 
            } 
            if (strApproDate.Trim.Length > 0 & strApproDate2.Trim.Length > 0) { 
                ass.Append(" And a.appro_date between '" + strApproDate + "' and '" + strApproDate2 + "' "); 
            } 
            string bss = ass.ToString(); 
            int RecordCount = 0; 
            
            dsResult = clsDBProcess.GetDataSet(Session("Server"), Session("Database"), bss); 
            RecordCount = Int32.Parse(dsResult.Tables(0).Rows(0)(0)); 
            return RecordCount; 
            msgbox.Text = RecordCount; 
        } 
        #endregion 
        #region "翻頁" 
        //下一頁 
        protected void // ERROR: Handles clauses are not supported in C# Nextpage_Click(object sender, System.EventArgs e) 
        { 
            CurrentPage = (int)ViewState("PageIndex"); 
            Pages = (int)ViewState("PageCounts"); 
            CurrentPage = CurrentPage + 1; 
            ViewState("PageIndex") = CurrentPage; 
            Session("CurPage") = CurrentPage; 
            CreatePagedDataSource(""); 
        } 
        //上一頁 
        protected void // ERROR: Handles clauses are not supported in C# Prevpage_Click(object sender, System.EventArgs e) 
        { 
            CurrentPage = (int)ViewState("PageIndex"); 
            Pages = (int)ViewState("PageCounts"); 
            CurrentPage -= 1; 
            ViewState("PageIndex") = CurrentPage; 
            Session("CurPage") = CurrentPage; 
            CreatePagedDataSource(""); 
        } 
        //最后一頁 
        protected void // ERROR: Handles clauses are not supported in C# Lastpage_Click(object sender, System.EventArgs e) 
        { 
            CurrentPage = (int)ViewState("PageIndex"); 
            Pages = (int)ViewState("PageCounts"); 
            CurrentPage = Pages; 
            ViewState("PageIndex") = CurrentPage; 
            Session("CurPage") = CurrentPage; 
            CreatePagedDataSource(""); 
        } 
        //第一頁 
        protected void // ERROR: Handles clauses are not supported in C# Fistpage_Click(object sender, System.EventArgs e) 
        { 
            CurrentPage = (int)ViewState("PageIndex"); 
            Pages = (int)ViewState("PageCounts"); 
            CurrentPage = 1; 
            ViewState("PageIndex") = CurrentPage; 
            Session("CurPage") = CurrentPage; 
            CreatePagedDataSource(""); 
        } 
        
        //轉到第幾頁 
        protected void // ERROR: Handles clauses are not supported in C# gotoPage_TextChanged(object sender, System.EventArgs e) 
        { 
            string asd = this.gotoPage.Text.Trim().ToString(); 
            JumpPage = (int)ViewState("JumpPages"); 
            if (string.IsNullOrEmpty(asd)) { 
                Alert("超出范围"); 
                return; 
            } 
            if (Int32.Parse(gotoPage.Text) > JumpPage || Int32.Parse(gotoPage.Text) <= 0 || string.IsNullOrEmpty(asd)) { 
                Alert("超出范围"); 
                return; 
            } 
            else { 
                int InputPage = Int32.Parse(gotoPage.Text.ToString()); 
                ViewState("PageIndex") = InputPage; 
                Session("CurPage") = InputPage; 
                CreatePagedDataSource(""); 
            } 
        } 

    #endregion 
      

  10.   

    public void CreatePagedDataSource(string strStringValue) 

        int intPage = 0; 
        string strMid = null; 
        string strSQL = ""; 
        DataSet dsResult = new DataSet(); 
        dbprocess.OledbProcess clsDBProcess = new dbprocess.OledbProcess(); 
        string strMidName = null; 
        string strGetDataFlag = null; 
        
        CurrentPage = (int)ViewState("PageIndex"); 
        Pages = (int)ViewState("PageCounts"); 
        if (CurrentPage > 1) { 
            Fistpage.Enabled = true; 
            Prevpage.Enabled = true; 
        } 
        else { 
            Fistpage.Enabled = false; 
            Prevpage.Enabled = false; 
        } 
        if (CurrentPage == Pages + 1) { 
            Nextpage.Enabled = false; 
            Lastpage.Enabled = false; 
        } 
        else { 
            Nextpage.Enabled = true; 
            Lastpage.Enabled = true; 
        } 
        try { 
            strGetDataFlag = Request.QueryString("getdata") + ""; 
            strMid = Request.QueryString("mid") + ""; 
            strMidName = GetMenuName(Session("Server"), Session("Database"), strMid); 
            tb1.Rows(0).Cells(0).InnerHtml = "&nbsp;<b>" + strMidName + "</b>"; 
            
            if (strGetDataFlag == "1") 
     StringBuilder strSQL2 = new StringBuilder("select * from (select a.rec_id,a.cls_num,a.emp_id,a.taken_hr,a.exam_result,a.finasst_per,ROW_NUMBER() OVER(ORDER BY a.rec_id) AS number from classes a  )T1 where number between cast('" & PageSize & "' as int) *(cast('" & CurrentPage & "' as int)-1)+1 and cast('" & PageSize & "' as int)*cast('" & CurrentPage & "' as int)")
                if (strClassNum.Trim.Length > 0) { 
                    strSQL2.Append(" And a.cls_num like '%" + strClassNum + "%'"); 
                } 
                if (strCourseNum.Trim.Length > 0) { 
                    strSQL2.Append(" And a.crs_num like '%" + strCourseNum + "%'"); 
                } 
                if (strfac.Trim.Length > 0) { 
                    strSQL2.Append(" And a.fac_num like '%" + strfac + "%'"); 
                } 
                if (strdept.Trim.Length > 0) { 
                    strSQL2.Append(" And a.dept_num like '%" + strdept + "%'"); 
                } 
                if (strApproStatus.Trim.Length > 0) { 
                    strSQL2.Append(" And a.appro_status like '%" + strApproStatus + "%'"); 
                } 
                if (strTutorID.Trim.Length > 0) { 
                    strSQL2.Append(" And a.emp_id like '%" + strTutorID + "%'"); 
                } 
                if (strApproDate.Trim.Length > 0 & strApproDate2.Trim.Length == 0) { 
                    strSQL2.Append(" And a.appro_date like '%" + strApproDate + "%' "); 
                } 
                if (strApproDate.Trim.Length > 0 & strApproDate2.Trim.Length > 0) { 
                    strSQL2.Append(" And a.appro_date between '" + strApproDate + "' and '" + strApproDate2 + "' "); 
                } 
                // strSQL &= " order by a.cls_num desc" 
                dsResult = clsDBProcess.GetDataSet(Session("Server"), Session("Database"), strSQL2.ToString); //這里可以改為自己的GetDataSet方法
                Repeater1.DataSource = dsResult; //這里可以改為 gridview 或datalist
                Repeater1.DataBind(); 
                LCurrentPage.Text = CurrentPage.ToString(); 
            } 
            //msgbox.Text = Pages.ToString() 
        } 
        catch (Exception ex) { 
            msgbox.Text = (ex.ToString); 
        } 
        finally { 
            dsResult = null; 
            clsDBProcess = null; 
        } 
      

  11.   


    这里说的是AspNetPager吗?如果是的话,那么楼主根本对这个控件不了解,AspNetPager和数据没有任何直接关系,它只是显示一系列分页按钮并引发一个分页事件而已,数据怎么获取以及从哪里获取都是用户自己来实现的,所谓的“没有针对大数据量做优化”纯属无稽之谈,因为AspNetPager根本不和数据源打交道。楼主完全可以使用AspNetPager配合你上面说的获取数据的方法来实现分页,
      

  12.   

    因为AspNetPager根本不和数据源打交道,所以没有针对大数据量做优化
      

  13.   

    protected void BindData() {
            initdb();
            OleDbDataAdapter sda = new OleDbDataAdapter("select * from t_product",conn);       
            DataSet ds = new DataSet();
            //sda.Fill(ds, 10, 10, "temptbl");
            sda.Fill(ds, pager1.PageSize * (pager1.CurrentPageIndex - 1), pager1.PageSize, "temptbl");
            DataList1.DataSource = ds.Tables["temptbl"];
            DataList1.DataBind();
        }
    AspNetPager是把所有数据取出来,再取一部分到gridview显示的。
    虽然分页效率也不错,但是把所有数据都读出来就浪费了服务器资源了。
      

  14.   

    protected void BindData() { 
            initdb(); 
            OleDbDataAdapter sda = new OleDbDataAdapter("select * from t_product",conn);      
            DataSet ds = new DataSet(); 
            //sda.Fill(ds, 10, 10, "temptbl"); 
            sda.Fill(ds, pager1.PageSize * (pager1.CurrentPageIndex - 1), pager1.PageSize, "temptbl"); 
            DataList1.DataSource = ds.Tables["temptbl"]; 
            DataList1.DataBind(); 
        } 
    AspNetPager是把所有数据取出来,再取一部分到gridview显示的。 
    虽然分页效率也不错,但是把所有数据都读出来就浪费了服务器资源了。错了,不知道你工作多少年了, AspNetPager 是跟数据没有任何的关系的, 只跟你传给总共有多少条数据,一页显示几条。是一个非常好的翻页控件,你这个,我刚毕业那阵子也是这么做程序的。没有任何可重复用性。 
      

  15.   

    Pager.ascx
    <%@ control language="c#" inherits="Troika.Ascx.Pager" CodeFile="~/Ascx/Pager.ascx.cs"%>
    <script  type="text/javascript">
    function callButtonEvent()
    {
    var keycode =window.event.keyCode;
    if(keycode==13)
    {
    if(check()==true)
    {
    event.cancelBubble=true;
    event.returnValue=false;
    document.getElementById('<%=btnGo.ClientID%>').click();
    }


    function check()
    {
    var count =  parseInt(document.getElementById('<%=lblTotal.ClientID%>').outerText);
    var txt = document.getElementById('<%=txtCurrentPage.ClientID%>').value;
    var cur = parseInt(txt);
    if ((cur | NaN) ==0) 
    {
    alert('Input page must format as integer.');
    event.cancelPostBack=true;
    return false;
    }
    if (cur > count || cur < 1)
    {
    alert('Input page no out of range.');
    event.cancelPostBack=true;
    return false;
    }
    }
    </script>
    <table  class="tablepagefoot" align="right">
    <tr>
    <td>
    页次&nbsp;<asp:literal id="lipagenum" Runat="server" />/<asp:literal id="lipageallnum" Runat="server" />&nbsp; 
    每页<asp:literal id="lipagesize" Runat="server" />条&nbsp; 共<asp:literal id="lirownum" Runat="server" />条&nbsp;
    <asp:LinkButton id="btnFirstPage" runat="server" CausesValidation="False" CommandArgument="First">首页</asp:LinkButton>&nbsp;
    <asp:LinkButton id="btnPrevPage" runat="server" CausesValidation="False" CommandArgument="Prev">上一页</asp:LinkButton>&nbsp;
    <asp:LinkButton id="btnNextPage" runat="server" CausesValidation="False" CommandArgument="Next">下一页</asp:LinkButton>&nbsp;
    <asp:LinkButton id="btnLastPage" runat="server" CausesValidation="False" CommandArgument="Last">尾页</asp:LinkButton>&nbsp;&nbsp;<ASP:TEXTBOX ID="txtCurrentPage" RUNAT="server" MAXLENGTH="5"  Width="35px">0</ASP:TEXTBOX>
    <input type="hidden" runat="server"  id="lblTotal" />
    <ASP:BUTTON ID="btnGo" RUNAT="server"  SkinId="btngoto" CausesValidation="False" COMMANDARGUMENT="Go" ToolTip="转到"></ASP:BUTTON>&nbsp;</td>
    </tr>
    </table>
      

  16.   

    Pager.ascx.cs
    namespace Troika.Ascx
    {
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
        //using Service; /// <summary>
    /// page 的摘要说明。
    /// </summary>
    public partial class Pager : System.Web.UI.UserControl
    {
    int size=10;//可以在web.config中配置
    public event System.EventHandler NavigationClick; protected void Page_Load(object sender, System.EventArgs e)
    {
    this.txtCurrentPage.Attributes.Add("onkeypress","callButtonEvent();");
    this.btnGo.Attributes.Add("onclick","check();");
    if(!this.IsPostBack)
    {
    SetStyle();
    SetEnable();
    }
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    this.btnFirstPage.Click += new System.EventHandler(this.btnGo_Click);
    this.btnPrevPage.Click += new System.EventHandler(this.btnGo_Click);
    this.btnNextPage.Click += new System.EventHandler(this.btnGo_Click);
    this.btnLastPage.Click += new System.EventHandler(this.btnGo_Click);
    this.btnGo.Click += new System.EventHandler(this.btnGo_Click);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    { }
    #endregion #region btnGo_Click
    public void btnGo_Click(object sender, System.EventArgs e)
    {
    LinkButton linkbtn = sender as LinkButton;
    if( null == linkbtn )//button
    {
    Button btn = sender as Button;
    if( null == btn )
    {
    return;
    }
    else
    {
    int selPage = -1;
    try
    {
    selPage =Int32.Parse(txtCurrentPage.Text);
    }
    catch
    {
    selPage = -1;
    }
    if (selPage > 0 && selPage <= PageCount)
    {
    ViewState["CurrentPageIndex"]  = selPage;
    }
    else
    {
    return;
    }
    }
    }
    else//linkbutton
    {
    switch ( linkbtn.CommandArgument.Trim() )
    {
    case "First":
    ViewState["CurrentPageIndex"] = 1;
    break;
    case "Prev":
    ViewState["CurrentPageIndex"] = (CurrentPageIndex > 1) ? CurrentPageIndex - 1 : 1;
    break;
    case "Next":
    ViewState["CurrentPageIndex"] = (PageCount > CurrentPageIndex) ? CurrentPageIndex + 1 : PageCount;
    break;
    case "Last":    
    ViewState["CurrentPageIndex"]  = PageCount;
    break;
    default:
    break;
    }
    }
    SetEnable();//设置显示样式
    if (NavigationClick!=null)//调用事件 
    {
    NavigationClick( sender,e );
    }
    }
    #endregion #region SetStyle
    private void SetStyle()
    {
    this.btnFirstPage.Attributes["style"] = "CURSOR: hand";
    this.btnLastPage.Attributes["style"] = "CURSOR: hand";
    this.btnNextPage.Attributes["style"] = "CURSOR: hand";
    this.btnPrevPage.Attributes["style"] = "CURSOR: hand";
    }
    #endregion #region SetEnable
    // 应根据当前的CurrentPageIndex和pageCount设定哪些按钮可用
    public void SetEnable()
    {
    this.lblTotal.Value =  PageCount.ToString();

    txtCurrentPage.Text =CurrentPageIndex.ToString();

    btnPrevPage.Enabled = false;
    btnNextPage.Enabled = false;

    if( PageCount >1 )
    {
    btnFirstPage.Enabled = btnPrevPage.Enabled = ( CurrentPageIndex >1 );
    btnNextPage.Enabled = btnLastPage.Enabled = ( CurrentPageIndex < PageCount );
    }
    else
    {
    btnFirstPage.Enabled = false;
    btnLastPage.Enabled = false;
    btnPrevPage.Enabled = false;
    btnNextPage.Enabled = false;
    }

    lipagenum.Text = CurrentPageIndex.ToString();
    lipageallnum.Text = PageCount.ToString();
                lipagesize.Text = PageSize.ToString();
    lirownum.Text = RecordCount.ToString();
     
    }

    #endregion #region Property
    //获取或设置当前显示页的索引。
    public int  CurrentPageIndex
    {
    get
    {
    object cpage=ViewState["CurrentPageIndex"];
    int pindex=(cpage==null)?1:(int)cpage;
                    //if(pindex>PageCount&&PageCount>0)
                    //    return PageCount;
                    //else if(pindex<1)
                    //    return 1;
    return pindex;
    }
    set
    {
    int cpage=value;
    if(cpage<1)
    cpage=1;
    // else if(cpage>this.PageCount)
    // cpage=this.PageCount;
    ViewState["CurrentPageIndex"]=cpage;
    }
    }
    // 获取或设置需要分页的所有记录的总数。
       public int RecordCount
    {
    get
    {
    object obj=ViewState["Recordcount"];
    return (obj==null)?0:(int)obj;
    }
    set
    {
    ViewState["Recordcount"]=value;
    SetEnable();
    }
    } //获取当前页之后的页的总数。
    public int PagesRemain
    {
    get
    {
    return PageCount-CurrentPageIndex;
    }
    }
    // 获取或设置每页显示的项数。
    public int PageSize
    {
    get
    {
    object obj=ViewState["PageSize"];
    if (obj==null)
    {
    obj= size;
    }
    return (obj==null)?size:(int)obj;
    }
    set
    {
    int pageSize = value;

    if (Math.Abs(pageSize) == 0)
    pageSize = size; ViewState["PageSize"]=pageSize;
    }
    } // 获取在当前页之后还未显示的剩余记录的项数。
    public int RecordsRemain
    {
    get
    {
    if(CurrentPageIndex<PageCount)
    {
    return RecordCount-(CurrentPageIndex*PageSize);
    }
    else
    {
    return 0;
    }
    }
    } // 获取所有要分页的记录需要的总页数。
    public int PageCount
    {
    get{return (RecordCount > 0) ? (int)Math.Ceiling((double)RecordCount/(double)PageSize) : 1;}
    } public int XRecord
    {
    get
    {
    return int.Parse( System.Configuration.ConfigurationSettings.AppSettings["XRecord"].Trim() );
    }
    }
    #endregion Property
    }
    }
      

  17.   

    21世纪什么最多,
      当然是人才啦,xixi
        
      

  18.   

    新年送QQ  有需要的朋友进我空间选号码,
       http://user.qzone.qq.com/75798353/infocenter