请各位帮忙看看这段ASP.NET中datagrid分页怎么不行?

 所属目录:Java   |   类型:技术问答   |   时间:2007-05-21
 问题:

<%@   import   namespace="system.data"   %>    
            <%@   import   namespace="system.data.sqlclient"   %>    
            <script   language="c#"   runat="server">    
            void   page_load(object   sender,   system.eventargs   e)  
          {  
            sqlconnection     myconnection;  
            sqlcommand     mycommand   ;  
            dataset   ds;    
            myconnection   =   new   sqlconnection("server=.;database=student;uid=sa;pwd="   );  
            myconnection.open();  
            la1.text="connection   opened!";    
            mycommand   =   new   sqlcommand(   "select   *   from   [student_info]",   myconnection   );    
            mydatagrid.datasource=mycommand.executereader();    
            mydatagrid.databind();    
          }    
            </script>    
            <html>    
            <body>    
            <asp:label   id="la1"   runat="server"   /><br>    
            <asp:datagrid   id="mydatagrid"   runat="server"  
            allowpaging="true"  
            pagesize="5"  
            pagerstyle-horizontalalign="right"  
            bordercolor="black"  
            borderwidth="1"  
            gridlines="both"  
            cellpadding="3"  
            cellspacing="0"  
            font-name="verdana"  
            font-size="8pt"  
            headerstyle-backcolor="#aaaadd"  
            alternatingitemstyle-backcolor="#eeeeee"  
  />  
            </body>    
            </html>    
   
   
   
  提示错误:当   allowpaging   设置为真并且选定的数据源不实现   icollection   时,allowcustompaging   必须为真,并且   id   为   mydatagrid   的   datagrid   必须设置   virtualitemcount。    
  说明:   执行当前   web   请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。    
   
  异常详细信息:   system.web.httpexception:   当   allowpaging   设置为真并且选定的数据源不实现   icollection   时,allowcustompaging   必须为真,并且   id   为   mydatagrid   的   datagrid   必须设置   virtualitemcount。  
   
 

· 网友精彩回答:

发表者:postfix2

分页的事件都没有加  
   
   
  private   void   gridaffair_pageindexchanged(object   source,   system.web.ui.webcontrols.datagridpagechangedeventargs   e)  
  {  
  this.gridaffair.currentpageindex   =   e.newpageindex;  
  this.datagridbind();  
  }  
 

发表者:egonzou

绑定datareader数据时你必须把datagrid的allowcustompaging属性设置为true  
  也就是说你得自定义分页,如果要用datagrid本身的分页的话,请用dataset吧

发表者:holysky

分页时,每次重新定义自动换页事件前,要重新邦定数据。否则,每次换页刷新datagrid是没有数据的

发表者:zq5143

对于启用分页功能,只能在datagrid控件的数据源实现了icollection接口的情况下启用分页功能。datareader没有实现这个接口,所以必须使用datatable来代替~~!

发表者:emanlee

在<script></script>之间添加分页时间代码:  
  private   void   mydatagrid_pageindexchanged(object   source,   system.web.ui.webcontrols.datagridpagechangedeventargs   e)  
  {  
  this.mydatagrid.currentpageindex   =   e.newpageindex;  
  this.datagridbind();  
  }  
 

.
处理 SSI 文件时出错
© 2006-2008 All Rights Reserved