asp.net 第三方控制實現分頁代碼的方法

來源:互聯網
上載者:User

AspNetPager是第三方控制項,下載地址:http://www.webdiyer.com/AspNetPagerDocs/index.html。

然後通過Visaul Studio 2005的“選擇項”把下載後的控制項DLL載入到我們的控制項工具箱中。
           <asp教程:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
                <Columns>
                    <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" />
                    <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
                    <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
                    <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" />
                    <asp:BoundField DataField="Address" HeaderText="Address" />
                    <asp:BoundField DataField="City" HeaderText="City" />
                </Columns>
            </asp:GridView>
            <webdiyer:AspNetPager ID="AspNetPager1" PageIndexBoxType="DropDownList" CustomInfoTextAlign="Left" FirstPageText="首頁"
                PrevPageText="上一頁" TextAfterPageIndexBox="頁" TextBeforePageIndexBox ="轉到" SubmitButtonText="Go"  ShowPageIndexBox ="Always" LastPageText="尾頁" NextPageText="下一頁" ShowCustomInfoSection="Left" CustomInfoHTML="當前%CurrentPageIndex%頁,共有%PageCount%頁"
                runat="server" OnPageChanging="AspNetPager1_PageChanging">
            </webdiyer:AspNetPager>
        </div>
///
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
        }
    }
    public void bind()
    {
        OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:Northwind.mdb");
        OleDbCommand cmd = new OleDbCommand("select * from Customers", con);
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
        PagedDataSource ps教程 = new PagedDataSource();
        ps.AllowPaging = true;
        ps.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
        ps.DataSource = ds.Tables[0].DefaultView;
        this.GridView1.DataSource = ps;
        this.GridView1.DataBind();
    }
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        bind();
    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.