asp.net分頁控制項使用詳解【附執行個體下載】

來源:互聯網
上載者:User

標籤:分頁控制項   private   XML   12px   targe   tco   div   help   protect   

本篇文章主要對asp.net建立事務的方法進行執行個體介紹,具有很好的參考價值,需要的朋友一起來看下吧

一、說明

AspNetPager.dll這個分頁控制項主要用於asp.net webform網站,現將整理代碼如下

二、代碼

1、首先在測試頁面Default.aspx頁面添加引用

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

2、寫一個Repeater清單控制項用於顯示資料

?
12345678 <asp:Repeater ID="rptNews" runat="server">  <ItemTemplate>    <li>      <span><%# Eval("time") %></span>      <a href="NewsShow.aspx?id=<%# Eval("id") %>"><%# Access.GetStringNum( Eval("name").ToString(),15) %></a>    </li>  </ItemTemplate></asp:Repeater>

3、添加

?
123456 <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" CustomInfoStyle="FONT-SIZE: 12px" FirstPageText="首頁" HorizontalAlign="Center" inputboxstyle="width:19px" LastPageText="尾頁" meta:resourcekey="AspNetPager1" NextPageText="下一頁" PageSize="10" PrevPageText="上一頁" Style="font-size: 14px" Width="95%" CssClass="anpager" CurrentPageButtonClass="cpb" OnPageChanging="AspNetPager1_PageChanging" ShowBoxThreshold="10"></webdiyer:AspNetPager> 

PageSize屬性是用於設定每頁顯示的數量

4、後台代碼綁定

Access是測試資料庫訪問類,在最後的Demo中提供給大家

5、分頁控制項點擊頁碼事件

?
123456 //分頁protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e){  this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;  ShowNews();}

最後奉上整頁代碼:

Default.aspx

?
1234567891011121314151617181920212223242526272829303132333435 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %><%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>asp.net分頁控制項</title> <link href="css/css.css" rel="stylesheet" type="text/css" /> <style type="text/css"> .aboutcontentnr{width:100%; height:auto; } </style></head><body> <form id="form1" runat="server"> <div> <ul class="news"> <asp:Repeater ID="rptNews" runat="server"> <ItemTemplate>  <li><span>  <%# Eval("time") %></span><a href="NewsShow.aspx?id=<%# Eval("id") %>"><%# Access.GetStringNum( Eval("name").ToString(),15) %></a></li> </ItemTemplate> </asp:Repeater> </ul> <div class="paginator"> <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" CustomInfoStyle="FONT-SIZE: 12px" FirstPageText="首頁" HorizontalAlign="Center" inputboxstyle="width:19px" LastPageText="尾頁" meta:resourcekey="AspNetPager1" NextPageText="下一頁" PageSize="10" PrevPageText="上一頁" Style="font-size: 14px" Width="95%" CssClass="anpager" CurrentPageButtonClass="cpb" OnPageChanging="AspNetPager1_PageChanging" ShowBoxThreshold="10"> </webdiyer:AspNetPager> </div> </div> </form></body></html>

Default.aspx.cs

?
12345678910111213141516171819202122232425262728293031 using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;public partial class Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ShowNews(); } } //測試資料來源 private void ShowNews() { String strSql = String.Format("select * from News order by time asc"); DataTable dtbl = Access.ExecuteDataTable(strSql, null); this.rptNews.DataSource = Access.GetPageDataSource(AspNetPager1, AspNetPager1.CurrentPageIndex - 1, dtbl); this.rptNews.DataBind(); } //分頁點擊頁碼事件 protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { this.AspNetPager1.CurrentPageIndex = e.NewPageIndex; ShowNews(); }}

三、Demo

  AspNetPager(dll)

  AspNetPage(Demo)

 以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的協助,同時也希望多多支援指令碼之家!

原文連結:http://www.cnblogs.com/lengzhan/p/6054583.html

asp.net分頁控制項使用詳解【附執行個體下載】

聯繫我們

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