zoukankan      html  css  js  c++  java
  • 简单控件分页

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ import namespace="System.Data" %>
    <%@ import namespace="System.Data.SqlClient" %>
    <script language="C#" runat="server">
    public void Page_Load(Object src,EventArgs e) {
        SqlConnection objConn = ConDB1.ConnectionDataBase();
    SqlDataAdapter objCommand = new SqlDataAdapter("select * from article_view", objConn);
    DataSet ds=new DataSet();
    objCommand.Fill(ds);

    PagedDataSource objPds = new PagedDataSource();
    objPds.DataSource = ds.Tables[0].DefaultView;
    objPds.AllowPaging = true;
    objPds.PageSize = 5;
    int CurPage;
    if(Request.QueryString["Page"] != null)
    CurPage=Convert.ToInt32(Request.QueryString["Page"]);
    else
    CurPage=1;

    objPds.CurrentPageIndex = CurPage-1;
    lblCurrentPage.Text = CurPage.ToString();

    if (!objPds.IsFirstPage)
    lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage-1);

    if (!objPds.IsLastPage)
    lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage+1);

    Repeater1.DataSource=objPds;
    Repeater1.DataBind();
    }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Repeater控件分页的例子</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <style>
    P,TD,DIV,SPAN {font-size:9pt}
    </style>
    </head>
    <body>
    <form id="Form1" name="form1" method="POST" runat="server">
    <div style="padding:5px;background-color:#dedede">
    <asp:label ID="lblCurrentPage" runat="server"></asp:label>
    &nbsp;<asp:HyperLink id="lnkPrev" runat="server">上一页</asp:HyperLink>
    <asp:HyperLink id="lnkNext" runat="server">下一页</asp:HyperLink>&nbsp;
    </div>
    <hr size="1" color="#000099"/>
    <asp:Repeater ID="Repeater1" runat="server">
    <Itemtemplate>
    <div style="padding:5px;background-color:#dedede">
    <%# DataBinder.Eval(Container.DataItem, "Title") %>
    </div>
    </Itemtemplate>
    </asp:Repeater>
    </form>
    </body>
    </html>

  • 相关阅读:
    不敢想,做个博客竟如此简单!
    我有一台服务器,能干啥?
    精品 IDEA 插件大汇总!值得收藏
    怒肝半月!Python 学习路线+资源大汇总
    怒肝 Linux 学习路线,这回不难
    多环境
    分享 10 个高星的创意项目!
    js的attribute
    选择大厂该做哪些准备?|小白进入大厂现状
    小白程序猿了解大厂的开发模式
  • 原文地址:https://www.cnblogs.com/a13971240/p/1316799.html
Copyright © 2011-2022 走看看