<%@ import namespace="system.data"%>
<%@ import namespace="system.data.sqlclient"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<asp:DataGrid ID="gr_list" runat="server" pagesize="3" AllowPaging="true" AutoGenerateColumns="true" PagerStyle-NextPageText="下一页" PagerStyle-PrevPageText="上一页">
</asp:DataGrid>
</body>
</html>
<script language="vb" runat="server">
sub page_load(sender as object,e as eventargs)
if not page.ispostback then
call binddata()
end if
end sub
sub binddata()
dim connstr as string
connstr="server=127.0.0.1;database=temp;uid=sa;pwd=lj8212119"
dim conn as sqlconnection=new sqlconnection(connstr)
conn.open()
dim sql as string="select * from xuqiang_Info"
dim comm as new sqlcommand(sql,conn)
dim dr as sqldatareader
dr = comm.ExecuteReader()
gr_list.datasource=dr
gr_list.databind()
end sub
sub chgpage(sender as object ,e as datagridpagechangedeventargs)
gr_list.currentpageindex=e.newpageindex
call binddata()
end sub
</script>我按书上写的程序,根据提示我加上了AllowCustomPaging="true"页面没问题了,可是不能分页,下一页上没有可以点击连接的痕迹,大家请帮帮我,或介绍一些适合asp.net初学者相关的网站错误显示:
Server Error in '/' Application.
--------------------------------------------------------------------------------AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID gr_list when AllowPaging is set to true and the selected datasource does not implement ICollection. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID gr_list when AllowPaging is set to true and the selected datasource does not implement ICollection.Source Error: The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:1. Add a "Debug=true" directive at the top of the file that generated the error. Example:  <%@ Page Language="C#" Debug="true" %>or:2) Add the following section to the configuration file of your application:<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.  Stack Trace: 
[HttpException (0x80004005): AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID gr_list when AllowPaging is set to true and the selected datasource does not implement ICollection.]
   System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) +2068
   System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +49
   System.Web.UI.WebControls.BaseDataList.DataBind() +23
   ASP.index_aspx.binddata() +109
   ASP.index_aspx.page_load(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731 
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 

解决方案 »

  1.   

    VirtualItemCount必须设置总纪录数VirtualItemCount和页面大小PageSize
      

  2.   

    必须给下面这两个变量赋值
    AllowCustomPaging = true;
    VirtualItemCount = ??;
      

  3.   

    dim dr as sqldatareader
    dr = comm.ExecuteReader()
    -----------------------------
    尽量不要用datareader作为分页datagrid的数据源!
    改用dataset
    http://blog.csdn.net/allenting/archive/2005/01/27/271073.aspx