Asp.NET 的aspnetpager分頁代碼

來源:互聯網
上載者:User

asp教程.net 的aspnetpager分頁代碼
 @ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="test_default" stylesheettheme="default" %>
<%...@ register assembly="aspnetpager" namespace="wuqi.webdiyer" tagprefix="webdiyer" %>
<html xmlns="http://www.111cn.net/1999/xhtml" >
<head runat="server">
    <title>無標題頁</title>
</head>

<body>
    <form id="form1" runat="server">
    <div>
        <asp:datalist id="datalist1" runat="server">
            <itemtemplate>
                productname:
                <asp:label id="productnamelabel" runat="server" text='<%# eval("productname") %>'>
                </asp:label><br />
                <br />
            </itemtemplate>
        </asp:datalist>
        <webdiyer:aspnetpager id="pager1" runat="server" onpagechanged="changepage"></webdiyer:aspnetpager>   
    </div>
    </form>
</body>
</html>

<%

using system;
using system.data;
using system.configuration;
using system.collections;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
using cpp114.tools.oledb;
using system.data.oledb;
using wuqi.webdiyer;

public partial class test_default : system.web.ui.page
...{
    protected oledbconnection conn = new oledbconnection();
    protected oledbcommand cmd = new oledbcommand();

    protected void page_load(object sender, eventargs e)
    ...{
        if (!ispostback) ...{
            initdb();
            conn.open();
            cmd.commandtext = "select count(*) from t_product";
            pager1.recordcount = (int)cmd.executescalar();
            conn.close();
            binddata();
                      
        }

    }


 
 //初始化連線物件
   

protected void initdb()...{
        conn.connectionstring = oledbtool.myconnstr + server.mappath(oledbtool.mydbname);
        cmd.connection = conn;       
    }

 //資料繫結

    protected void binddata() ...{
        initdb();
        oledbdataadapter sda = new oledbdataadapter("select * from t_product",conn);      
        dataset ds = new dataset();
        //sda.fill(ds, 10, 10, "temptbl");
        sda.fill(ds, pager1.pagesize * (pager1.currentpageindex - 1), pager1.pagesize, "temptbl");
        datalist1.datasource = ds.tables["temptbl"];
        datalist1.databind();
    }

 //翻頁事件

    protected void changepage(object src, pagechangedeventargs e)
    ...{
        pager1.currentpageindex = e.newpageindex;
        binddata();
    }   

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.