• 在repeater、datalist控件中使用分页功能


    repeater和datalist控件可以很快的、灵活地在.aspx页面上显示数据,但
    它们都没有分页功能;虽然datagrid控件有分页功能,但使用起来却太古板了、灵活性太差了。
    很多文章都在讨论repeater、datalist的分页功能的问题,下面我们就用
    pagedatasource这个类在repeater中进行分页:
    pagedatasource是datagrid中封装的一个类,datagrid就是用这个来实现分页功能的;
    我们也可以用这个类在datalist、repeater中进行分页,大家只要看了下面的程序示例
    问题就可以解决了。
      

    <%@Import namespace="System.Data"%>
    <%@Import namespace="System.Data.SqlClient"%>
    <html>
    <head>
    <title>default</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="C#" runat="server">
    public void Page_Load(Object src,EventArgs e)
    {SqlConnection cnn=new SqlConnection("server=zzl;uid=sa;pwd=970480;database=zzl");//连接数据库
    SqlDataAdapter mycommand=new SqlDataAdapter("select * from start1",cnn);//数据操作,而表start1及其数据自己sqlserver中做
    DataSet ds=new DataSet();
    mycommand.Fill(ds);      //实例dataset对象为ds,并把数据填充到ds上


    PagedDataSource pp=new PagedDataSource();//对分页功能的类实例对象
    pp.DataSource=ds.Tables[0].DefaultView;//把数据赋予对象pp
    pp.AllowPaging=true;//允许进行分页
    pp.PageSize=6;//设置每页数据的个数
    int cpage;//这个整数用来分析分页页数的
    if(Request.QueryString["page"]!=null)//这个判断语句的作用是对cpage进行赋值
    cpage=Convert.ToInt32(Request.QueryString["page"]);
    else
    cpage=1;
    pp.CurrentPageIndex=cpage-1;//pp对象的当前引索值,因为引索值是从0开始,cpage从1开始所以要减1
    if (!pp.IsFirstPage)//Request.CurrentExecutionFilePath为当前的程序的文件名,直接写也可以
      pre.NavigateUrl=Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(cpage-1);

     if (!pp.IsLastPage)
      next.NavigateUrl=Request.CurrentExecutionFilePath+ "?page=" + Convert.ToString(cpage+1);
      
    repeater1.DataSource=pp;
    repeater1.DataBind();}
    </script>
    </head>
    <body>
    <table width="100%" border="0">
      <tr><TD>&nbsp;&nbsp;<asp:label id="current" runat="server"/></TD></tr>
      <tr><td>&nbsp;<asp:hyperlink id="pre" runat="server"><<</asp:hyperlink>
      <asp:hyperlink id="next" runat="server">>></asp:hyperlink></td></tr></table>
      <asp:repeater id="repeater1" runat="server">
        <itemtemplate>
     <table width="100%" border="0">
     <tr><td>&nbsp;&nbsp;<%#DataBinder.Eval(Container.DataItem,"product")%></td></tr>
     <tr><td>&nbsp;&nbsp;</td></tr></table></itemtemplate></asp:repeater>
    </body>
    </html>

  • 相关阅读:
    2013.4.15 Particle Swarm Optimization with Skyline Operator for Fast Cloudbased Web Service Composition
    Adaptive service composition in flexible processes
    2013.4.13 DomainSpecific Service Selection for Composite Services
    2013.4.14 Modeling and Algorithms for QoSAware Service Composition in VirtualizationBased Cloud Computing
    2013.5.29 Towards Networkaware Service Composition in the Cloud
    Efficient algorithms for Web services selection with endtoend QoS constraints
    SQL Server中常用的SQL语句
    接口限流自定义注解
    linux服务器生产环境搭建
    MVEL自定义函数重复掉用报错:duplicate function
  • 原文地址:https://www.cnblogs.com/King0502/p/2019413.html
Copyright © 2020-2023  润新知