AspNetPager分頁控制項使用方法

來源:互聯網
上載者:User

標籤:

一、下載AspNetPager.dll二、AspNetPager.dll複製於應用程式下的bin目錄,開啟解決方案,引用dll檔案三、 在工具列中添加控制項,這樣可以支援拖拽使用四、 要使用AspNetPager 要為其設定最基本的屬性樣本:

1、前台顯示介面代碼Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default4" %><%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"><title>用AspNetPager.dll控制項的分頁方法操作方法</title></head><body><form id="form1" runat="server"><div><table border=1><asp:Repeater ID="Repeater1" runat="server"><ItemTemplate><tr><td><%#DataBinder.Eval(Container.DataItem,"osid")%></td><td><%#DataBinder.Eval(Container.DataItem,"year1")%></td><td><%#DataBinder.Eval(Container.DataItem,"month1")%></td><td><%#DataBinder.Eval(Container.DataItem,"output1")%></td></tr></ItemTemplate></asp:Repeater></table><webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" NumericButtonCount="6" UrlPaging="true" NumericButtonTextFormatString="[{0}]"CustomInfoHTML="第 <font color=‘red‘><b>%CurrentPageIndex%</b></font> 頁 共 %PageCount% 頁 顯示 %StartRecordIndex%-%EndRecordIndex% 條"ShowCustomInfoSection="left"FirstPageText="首頁" LastPageText="末頁" NextPageText="下頁" PrevPageText="上頁" Font-Names="Arial" BackColor="#F8B500" AlwaysShow="true"ShowInputBox="Always" SubmitButtonText="跳轉" SubmitButtonStyle="botton" OnPageChanged="AspNetPager1_PageChanged" ></webdiyer:AspNetPager></div></form></body></html>
View Code

 

紅框為分頁相關代碼


2、Default.aspx.cs頁面的代碼

DBAccess db = new DBAccess();protected void Page_Load(object sender, EventArgs e){if (!Page.IsPostBack){ BindGrid(); }}protected void AspNetPager1_PageChanged(object sender, EventArgs e){ BindGrid();}public void BindGrid(){this.AspNetPager1.RecordCount = Int32.Parse(db.GetAllCount().ToString());int pageIndex = this.AspNetPager1.CurrentPageIndex - 1;int pageSize = this.AspNetPager1.PageSize = 20;Repeater1.DataSource = db.GetCurrentPage(pageIndex, pageSize);Repeater1.DataBind();}三、DBAccess.cs頁面的代碼using System.Data.SqlClient;public class DBAccess{private SqlConnection con;private string DBName = "tongjinet";//建立連線物件並開啟public void Open(){if (con == null)con = new SqlConnection("server=(local);uid=sa;pwd=sql;database=" + DBName);if (con.State == ConnectionState.Closed)con.Open();}//建立一個命令對象並返回該對象public SqlCommand CreateCommand(string sqlStr){Open();SqlCommand cmd = new SqlCommand();cmd.CommandType = CommandType.Text;cmd.CommandText = sqlStr;cmd.Connection = con;return cmd;}//產生一個對象並返回該結果集第一行第一列public object GetScalar(string sqlStr){SqlCommand cmd = CreateCommand(sqlStr);object obj = cmd.ExecuteScalar();//CommadnBehavior.CloseConnection是將於DataReader的資料庫連結關聯起來//當關閉DataReader對象時候也自動關閉連結return obj;}//執行資料庫查詢並返回一個資料集 [當前頁碼,每頁記錄條數]public DataSet GetCurrentPage(int pageIndex, int pageSize){//設定匯入的起始地址int firstPage = pageIndex * pageSize;string sqlStr = "select * from outputsell order by osid desc";SqlCommand cmd = CreateCommand(sqlStr);DataSet dataset = new DataSet();SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);dataAdapter.Fill(dataset, firstPage, pageSize, "outputsell");cmd.Dispose();Close();dataAdapter.Dispose();return dataset;}//獲得查詢資料的總條數public object GetAllCount(){string sqlStr = "select count(*) from outputsell";object obj = GetScalar(sqlStr);return obj;}//關閉資料庫public void Close(){if (con != null){con.Close();}}//釋放資源public void Dispose(){if (con != null){con.Dispose();con = null;}}}
View Code

代碼參考:http://www.cnblogs.com/taizhouxiaoba/archive/2009/03/23/1419822.html

AspNetPager分頁控制項使用方法

聯繫我們

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