datagrid 自定义分页问题
数据源是datareader是不是不能使用内置分页功能?
求自定义分页实例代码?vb的!

解决方案 »

  1.   

    CREATE PROCEDURE pageTest  --用于翻页的测试
    --需要把排序字段放在第一列 (
      @FirstID nvarchar(20)=null,  --当前页面里的第一条记录的排序字段的值
      @LastID nvarchar(20)=null,  --当前页面里的最后一条记录的排序字段的值
      @isNext bit=null,    --true 1 :下一页;false 0:上一页
      @allCount int output,   --返回总记录数
      @pageSize int output,   --返回一页的记录数
      @CurPage int     --页号(第几页)0:第一页;-1最后一页。
      )ASif @CurPage=0
     begin
      --统计总记录数
      select @allCount=count(ProductId) from Product_test 
       
      set @pageSize=10
      --返回第一页的数据
      select top 10 
       ProductId,
       ProductName,
       Introduction   
       from Product_test order by ProductId 
     endelse if @CurPage=-1 select * from 
      (select top 10 ProductId,
       ProductName,
       Introduction  from Product_test order by ProductId desc ) as aa  
      order by ProductId
    else begin 
      if @isNext=1
       --翻到下一页
       select top 10 ProductId,
       ProductName,
       Introduction
      from Product_test where ProductId > @LastID order by ProductId 
       
       
      else
       --翻到上一页
       select * from
        (select top 10 ProductId,
       ProductName,
       Introduction
      from Product_test where ProductId < @FirstID  order by ProductId desc) as bb order by ProductId
     end
    声明:上述转载
      

  2.   

    1、是的。
    2、http://dev.csdn.net/develop/article/52/52203.shtm
      

  3.   

    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vbtskSpecifyingPagingBehaviorInDataGridWebControl.htm
      

  4.   

    看看这个!
    <%@ page language=vb debug=true%>
    <%@ register tagprefix="romantic" namespace="fw" assembly="tec_message" %>
    <html>
    <head>
    <title>
    </title>
    <style>
    body{scrollbar-face-color:#FFCC99;scrollbar-track-color:#FFaa66;scrollbar-arrow-color:red;scrollbar-shadow-color:#FFaa99}
    body{font-size:9pt}
    table{font-size:9pt}
    input{font-size:9pt}
    a:link{text-decoration:none;color:#000000}
    a:hover{text-decoration:none;color:red}
    a:visited{text-decoration:none;color:#000000}
    body{margin-top:10px;margin-left:0px;margin-bottom:5px;margin-right:0px}</style>
    <script language=vb runat=server>
    dim page1 as string
    dim i,j as integer
    dim n as integer
    dim strsql as string
    dim strcnn as string
    dim thenote as string
    sub page_load(sender as object, e as eventargs)
    button11.attributes.add("onclick","return window.confirm('你要删除,确认吗?');")
    page1=request("page")
    bind()
    if not ispostback then
    bindgrid11()
    end if
    end sub 
    public function disp(filename as integer) as integer
    n=dg.currentpageindex\10
    return n
    end functionfunction bindgrid11()
    dim fw as new tec_message
    dg.pagesize=10
    dg.currentpageindex=page1
    dg.datasource=fw.showarticle
    dg.databind()
    end functionsub bind()
    dim fw as new tec_message
    fw.count
    thenote=fw.thenote
    end subsub delete(sender as object, e as eventargs)
    dim fw as new tec_message
    fw.noteid=request.form("chk")
    if fw.delete then
    bindgrid11()
    bind()
    else
    response.write("<script language='javascript'>alert('删除失败!');<" & chr(47) & "script>")
    end if
    end sub
    </script>
    </head>
    <body bgcolor="#ffcc99">
    <form runat=server>
    <table width=100% cellpadding=2 cellspacing=1 bgcolor="#aab7b7">
    <tr height=25><th background=new/tiao1.jpg>.NET技术</th></tr>
    <tr bgcolor=#ffffff><td>
    <asp:datagrid 
    id=dg
    runat="server"
    BorderWidth="0"
    autocustompaging="true"
    AutoGenerateColumns="false"
    showheader=true
    headerstyle-backcolor="#aa56a1"
    cellpadding=2
    cellspacing=1
    allowpaging=true
    backcolor=#ffcc99
    width=100% >
    <pagerstyle visible=false/>
    <columns>
    <asp:templatecolumn
    headertext="删除"
    headerstyle-height=23
    headerstyle-width=5%
    itemstyle-backcolor=#ffffff
    itemstyle-horizontalalign=center>
    <itemtemplate>
    <input type='checkbox' name="chk" value='<%#databinder.eval(container.dataitem,"renoteid")%>'>
    </itemtemplate>
    </asp:templatecolumn>
    <asp:templatecolumn
    headertext="标题"
    headerstyle-width=13%
    itemstyle-backcolor=#ffffff
    >
    <itemtemplate>
    <a href=tecview.aspx?noteid=<%# databinder.eval(container.dataitem,"noteid")%> target="_blank"><%#container.dataitem("title")%></a>
    </itemtemplate>
    </asp:templatecolumn>
    <asp:templatecolumn
    headertext="内容"
    headerstyle-width=45%
    itemstyle-backcolor=#ffffff
    >
    <itemtemplate>
    <%#container.dataitem("content")%>
    </itemtemplate>
    </asp:templatecolumn>
    <asp:templatecolumn
    headertext="ip"
    headerstyle-width=12%
    itemstyle-backcolor=#ffffff
    >
    <itemtemplate>
    <%#container.dataitem("ip")%>
    </itemtemplate>
    </asp:templatecolumn>
    <asp:templatecolumn
    headertext="时间"
    headerstyle-width=13%
    itemstyle-backcolor=#ffffff
    >
    <itemtemplate>
    <%#container.dataitem("ttime")%>
    </itemtemplate>
    </asp:templatecolumn>
    </columns>
    </asp:datagrid>
    </td>
    <tr bgcolor=#ffffff height=35><td>
     总共<%=dg.pagecount%>页,共<%=thenote%>篇文章,当前第<font color=red><%=dg.currentpageindex+1%></font>页&nbsp;&nbsp;
    <%
    if dg.currentpageindex<>0 then
    response.write("<a href='tec_message.aspx?page=0'><font face=webdings>9</font></a>")
    else
    response.write("<font face=webdings color=red>9</font>")
    end if
    %>
    <% if page1>0 then
    response.write("<a href='tec_message.aspx?page=" & dg.currentpageindex-1 &"'><font face=webdings>7</font></a>")
    else
    response.write("<font face=webdings color=red>7</font>")
    end if
    %>
    <% 
    for i=0 to dg.pagecount-1
    disp(dg.currentpageindex)
    for j=n*10 to (n*10+9)
    if j=dg.currentpageindex then
    response.write("<font color=red>" & j+1 & "</font>&nbsp;") 
    else
    response.write("<a href='tec_message.aspx?&page=" & j &"'>" & j+1 & "</a>&nbsp;") 
    end if
    if j>dg.pagecount-2 then
    exit for
    end if
    next j 
    exit for
    next i
    %>
    <% if page1<dg.pagecount-1 then
    response.write("<a href='tec_message.aspx?page=" & dg.currentpageindex+1 &"'><font face=webdings>8</font></a>")
    else
    response.write("<font face=webdings color=red>8</font>")
    end if
    %>
    <% if page1<dg.pagecount-1 then
    response.write("<a href='tec_message.aspx?page=" & dg.pagecount-1 &"'><font face=webdings>:</font></a>")
    else
    response.write("<font face=webdings color=red>:</font>")
    end if
    %>&nbsp;
    </td></tr>
    <tr bgcolor=#ffffff height=35><td>注意:左边复选框为删除选项,如果选择后点删除设置,则删除相应图片
    如仅仅修改文件名,可在修改相应选项后直接点击修改设置 </td></tr>
    <tr bgcolor=#ffffff height=35><td align=center><asp:button id=button11 runat=server text=确认删除 onclick="delete"/></td></tr>
    </table>
    <br>
    </form>
    </body>
    </html>
      

  5.   

    datareader做数据源的时候是不能用内置的分页功能的,用dataset就可以
      

  6.   

    用datareader实现datagrid的自定义分页,要先给datagrid的VirtualItemCount赋值,把记录的count赋给他就行 了