当前位置:首页
开发技术指南» 文章正文
    引言:

 ·一个简单的问题    »显示摘要«
    摘要: 由于站点限制了某些ip才能访问.我想通过代码来伪造一个数据包请求该页面.请问如何实现?当然在这里,我不需要获得请求后反馈的信息,单单伪造一个客户端的ip即可.所以理论上应该可以实现.在此求代码方案. ......
    摘要: --drop table tgongwen --create table tgongwen( --[did] [int] identity(1,1) not null primary key check(did > 0), --title varchar(80) default null, --fariqi datetime null, --neibuyonghu varchar(7......


——————求AspNetPager分页的简单明了的例子请各位前辈指点谢谢200分

数据库文件   d:\data\db.mdb  
  里面有一张表news,关键字news_id  
   
  用OleDbConnection   +   OleDbDataAdapter   +   DataSet   +   datalist显示数据,用AspNetPager分页控件分页,每页10条记录,该如何写程序?  
  我看了很多例子,可是真的看不懂!  
  请各位前辈帮帮忙!最简单明了的写法就行!  
   
   
  实在   要崩溃了!  
  谢谢!谢谢!谢谢指点!

NO.1   作者: hubinasm

你看他里面的代码啊   里面都有例子的

NO.2   作者: zahota

如果是连续自增字段的话,可以根据自增字段查询如:select   *   from   where   id>10   and   id<20  
   
   
  如果数据量不大,可以使用DATASET如:  
  for(i=10;i<20;i++)  
        ds["table"].rows[i]["name"].tostring()  
   
  或者查询的时候利用排序和TOP关键字和子查询结合如  
  "select   top   10   *   from   (select   top   "   +   开始的记录数   +"   *   from   tablename     order   by   id   desc)   order   by   id   asc   "

NO.3   作者: BNFlying

学习

NO.4   作者: stoneyu

如果数据不是太大的话(如少于50W),用not   in就行了.  
  select     +pagesize   +字段名..+from   tablename   where+查询条件   +排序   not   in(select     +pagesize*(currentpage-1)   +字段名..+from   tablename   where+查询条件   +排序)  
   
  aspnetpager用于分页的信息就是pagesize和currentpage,所以在不能使用存储过程的情况下,以上能够简单实现.

NO.5   作者: bingbingcha

这个是完整的分页例子..刚好完全符合你的要求OleDbConnection   +   OleDbDataAdapter   +   DataSet   +   datalist..呵呵...把数据库路径和字段修改下就可以了  
   
  <%   @   Page   Language="C#"   %>  
  <%   @   Import   Namespace="System.Data"   %>  
  <%   @   Import   Namespace="System.Data.OleDb"   %>  
  <Script   Language="C#"   Runat="Server">  
  OleDbConnection   MyConn;  
  int   PageSize,RecordCount,PageCount,CurrentPage;  
  public   void   Page_Load(Object   src,EventArgs   e)  
  {  
  //设定PageSize  
  PageSize   =   5;  
   
  //连接语句  
  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")   %>  
  </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>  
 

NO.6   作者: smile9961

里面的例子很容易看懂的,仔细点;另外别忽视了它下面的存储过程,少了存储过程就不能分页了.

NO.7   作者: kqh0319

好好学习

NO.8   作者: ld_thinking

recordCount   属性是关键


    摘要: 比如1出现概率为0.4,2是0.1,3是0.2,4是0.3。程序应该怎么写出每次回出现什么数? ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE