首页   |   IT资讯   |   综合资讯   |   开发   |   软件   |   问答   |   网络技术   |   网络综合
更多:
当前位置:首页 » 手机数码
文章正文

谁有DATALIST分页控件,说明如何使用!

类型:转载   责任编辑:asp   日期:2007/03/01

    

谁有datalist分页控件,说明如何使用!

推荐阅读

  • 通过高速DSL建立VPN [详细内容]
  • 再次讨论图片DIY中的RGB值问题 [详细内容]
  • 三星纠正传闻 称无意涉足在线音乐服务市场 [详细内容]
  • 全能音乐塞班机SENDOX低价热销仅1580 [详细内容]
  • 轻松架设Peer to Peer VPN [详细内容]
  • AMD透露65NM工艺时间表 可能落后英特尔九个月 [详细内容]
  • 用价格挑战IXUS750!卡西欧Z750降100 [详细内容]
  • 网友回答:
    网友:jshadow

    这个是决定好的分页控件:  
       
       
      <%   @   page   language="c#"   %>  
      <%   @   import   namespace="system.data"   %>  
      <%   @   import   namespace="system.data.oledb"   %>  
      <script   language="c#"   runat="server">  
      /*  
        create   by   飞刀  
        http://www.aspcn.com  
        2001-7-25   01:44  
       
        support   .net   framework   beta   2  
      */  
      oledbconnection   myconn;  
      int   pagesize,recordcount,pagecount,currentpage;  
      public   void   page_load(object   src,eventargs   e)  
      {  
        //设定pagesize  
        pagesize   =   10;  
       
        //连接语句  
        string   myconnstring   =   "provider=microsoft.jet.oledb.4.0;   data   source="+server.mappath(".")+"..\\database\\db1.mdb;";  
        myconn   =   new   oledbconnection(myconnstring);  
        myconn.open();  
       
        //第一次请求执行  
        if(!page.ispostback)  
        {  
          listbind();  
          currentpage   =   0;  
          viewstate["pageindex"]   =   0;  
       
          //计算总共有多少记录  
          recordcount   =   calculaterecord();  
          lblrecordcount.text   =   recordcount.tostring();  
       
          //计算总共有多少页  
          pagecount   =   recordcount/pagesize;  
          lblpagecount.text   =   pagecount.tostring();  
          viewstate["pagecount"]   =   pagecount;  
        }  
      }  
      //计算总共有多少条记录  
      public   int   calculaterecord()  
      {  
        int   intcount;  
        string   strcount   =   "select   count(*)   as   co   from   score";  
        oledbcommand   mycomm   =   new   oledbcommand(strcount,myconn);  
        oledbdatareader   dr   =   mycomm.executereader();  
        if(dr.read())  
        {  
          intcount   =   int32.parse(dr["co"].tostring());  
        }  
        else  
        {  
          intcount   =   0;  
        }  
        dr.close();  
        return   intcount;  
      }  
       
      icollection   createsource()  
      {  
       
        int   startindex;  
       
        //设定导入的起终地址  
        startindex   =   currentpage*pagesize;  
        string   strsel   =   "select   *   from   score";  
        dataset   ds   =   new   dataset();  
       
        oledbdataadapter   myadapter   =   new   oledbdataadapter(strsel,myconn);  
        myadapter.fill(ds,startindex,pagesize,"score");  
       
        return   ds.tables["score"].defaultview;  
      }  
      public   void   listbind()  
      {  
        score.datasource   =   createsource();  
        score.databind();  
       
        lbnnextpage.enabled   =   true;  
        lbnprevpage.enabled   =   true;  
        if(currentpage==(pagecount-1))   lbnnextpage.enabled   =   false;  
        if(currentpage==0)   lbnprevpage.enabled   =   false;  
        lblcurrentpage.text   =   (currentpage+1).tostring();  
       
      }  
       
      public   void   page_onclick(object   sender,commandeventargs   e)  
      {  
        currentpage   =   (int)viewstate["pageindex"];  
        pagecount   =   (int)viewstate["pagecount"];  
       
        string   cmd   =   e.commandname;  
        //判断cmd,以判定翻页方向  
        switch(cmd)  
        {  
          case   "next":  
            if(currentpage<(pagecount-1))   currentpage++;  
            break;  
          case   "prev":  
            if(currentpage>0)   currentpage--;  
            break;  
        }  
       
        viewstate["pageindex"]   =   currentpage;  
       
        listbind();  
       
      }  
      </script>  
      <html>  
      <head>  
      <title></title>  
      </head>  
      <body>  
      <form   runat="server">  
      共有<asp:label   id="lblrecordcount"   forecolor="red"   runat="server"   />条记录&nbsp;  
      当前为<asp:label   id="lblcurrentpage"   forecolor="red"   runat="server"   />/<asp:label   id="lblpagecount"   forecolor="red"   runat="server"   />页&nbsp;  
       
      <asp:datalist   id="score"   runat="server"  
      headerstyle-backcolor="#aaaadd"  
      alternatingitemstyle-backcolor="gainsboro"  
      edititemstyle-backcolor="yellow"  
      >  
        <itemtemplate>  
          姓名:<%#   databinder.eval(container.dataitem,"name")   %>  
          <asp:linkbutton   id="btnselect"   text="编辑"   commandname="edit"   runat="server"   />  
        </itemtemplate>  
      </asp:datalist>  
      <asp:linkbutton   id="lbnprevpage"   text="上一页"   commandname="prev"   oncommand="page_onclick"   runat="server"   />  
      <asp:linkbutton   id="lbnnextpage"   text="下一页"   commandname="next"   oncommand="page_onclick"   runat="server"   />  
       
      </form>  
      </body>  
      </html>  
     

    .
      最佳浏览:1024X768 MSIE
    ©2007 jqmk.com.cn All Rights Reserved