在VS2005下使用Webdiyer:AspNetPager完美實現多種樣式分頁[轉]

注: 如果只想讓第一頁、上一頁等四個按鈕爲圖片按鈕而頁索引和更多頁鏈接爲文本,則還應將NumericButtonType和MoreButtonType設爲text。

在class.cs調用時,首先引入命名空間, 再把對象實例化.

如: AspNetPager anp = new AspNetPager();
        ada.Fill(ds, anp.PageSize * (anp.CurrentPageIndex - 1), anp.PageSize,"name"); //name爲表名

===============================================================================

 

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

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<%@ Import Namespace="System.Data"%>
           <%@Import Namespace="System.Data.SqlClient"%>
           <%@Import Namespace="System.Configuration"%>



<!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">
   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
        </div>
       <Webdiyer:AspNetPager id="AspNetPager1"
           runat="server"
           PageSize="8"
           NumericButtonCount="8"
           ShowCustomInfoSection="left"
           PagingButtonSpacing="0"
           ShowInputBox="always"
           CssClass="mypager"
           HorizontalAlign="right"
           SubmitButtonText="轉到"
           NumericButtonTextFormatString="[{0}]" OnPageChanged="AspNetPager1_PageChanged"/>
       
       <asp:DataList ID="DataList2" runat="server">
           <ItemTemplate>
               id:
               <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>'></asp:Label><br />
               news_title:
               <asp:Label ID="news_titleLabel" runat="server" Text='<%# Eval("news_title") %>'>
               </asp:Label><br />
               news_class:
               <asp:Label ID="news_classLabel" runat="server" Text='<%# Eval("news_class") %>'>
               </asp:Label><br />
               news_pubdate:
               <asp:Label ID="news_pubdateLabel" runat="server" Text='<%# Eval("news_pubdate") %>'>
               </asp:Label><br />
               news_content:
               <asp:Label ID="news_contentLabel" runat="server" Text='<%# Eval("news_content") %>'>
               </asp:Label><br />
               news_author:
               <asp:Label ID="news_authorLabel" runat="server" Text='<%# Eval("news_author") %>'>
               </asp:Label><br />
               news_input:
               <asp:Label ID="news_inputLabel" runat="server" Text='<%# Eval("news_input") %>'>
               </asp:Label><br />
               news_senddate:
               <asp:Label ID="news_senddateLabel" runat="server" Text='<%# Eval("news_senddate") %>'>
               </asp:Label><br />
               news_from:
               <asp:Label ID="news_fromLabel" runat="server" Text='<%# Eval("news_from") %>'></asp:Label><br />
               news_file:
               <asp:Label ID="news_fileLabel" runat="server" Text='<%# Eval("news_file") %>'></asp:Label><br />
               news_filetype:
               <asp:Label ID="news_filetypeLabel" runat="server" Text='<%# Eval("news_filetype") %>'>
               </asp:Label><br />
               news_type:
               <asp:Label ID="news_typeLabel" runat="server" Text='<%# Eval("news_type") %>'></asp:Label><br />
               news_hits:
               <asp:Label ID="news_hitsLabel" runat="server" Text='<%# Eval("news_hits") %>'></asp:Label><br />
               <br />
           </ItemTemplate>
       </asp:DataList>
   </form>
</body>
</html>


==============================================================================

==============================================================================
  1. using System;   
  2. using System.Data;   
  3. using System.Configuration;   
  4. using System.Web;   
  5. using System.Web.Security;   
  6. using System.Web.UI;   
  7. using System.Web.UI.WebControls;   
  8. using System.Web.UI.WebControls.WebParts;   
  9. using System.Web.UI.HtmlControls;   
  10. using System.Data.SqlClient;   
  11.   
  12. public partial class _Default : System.Web.UI.Page    
  13. {   
  14.     protected void Page_Load(object sender, EventArgs e)   
  15.     {   
  16.   
  17.         if (!Page.IsPostBack)   
  18.         {   
  19.             string strConn = "Data Source=localhost;Initial Catalog=zcls;Persist Security Info=True;User ID=sa;Password=windows";   
  20.             SqlConnection myConnection = new SqlConnection(strConn);   
  21.             string strsql = "SELECT count([id]) FROM [news] where id>6000";   
  22.             SqlCommand myCommand = new SqlCommand(strsql, myConnection);   
  23.             myCommand.CommandType = CommandType.Text;   
  24.             SqlDataAdapter myda = new SqlDataAdapter();   
  25.             myda.SelectCommand = myCommand;   
  26.             DataSet ds = new DataSet();   
  27.             myda.Fill(ds, "news");   
  28.             this.AspNetPager1.RecordCount = System.Convert.ToInt32(ds.Tables[0].Rows[0][0]);   
  29.             BindData();   
  30.         }   
  31.     }   
  32.   
  33.     void BindData()   
  34.     {   
  35.         string strConn = "Data Source=localhost;Initial Catalog=zcls;Persist Security Info=True;User ID=sa;Password=windows";   
  36.         SqlConnection myConnection = new SqlConnection(strConn);   
  37.         string strsql = "SELECT * FROM [news] where id>6000";   
  38.         SqlCommand myCommand = new SqlCommand(strsql, myConnection);   
  39.         myCommand.CommandType = CommandType.Text;   
  40.         SqlDataAdapter myda = new SqlDataAdapter();   
  41.         myda.SelectCommand = myCommand;   
  42.         DataSet ds = new DataSet();   
  43.         myda.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "news");   
  44.         this.DataList2.DataSource = ds.Tables["news"];   
  45.         this.DataList2.DataBind();   
  46.         //動態設置用戶自定義文本內容    
  47.         AspNetPager1.CustomInfoHTML = "記錄總數:<font color=/"blue/"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";   
  48.         AspNetPager1.CustomInfoHTML += " 總頁數:<font color=/"blue/"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";   
  49.         AspNetPager1.CustomInfoHTML += " 當前頁:<font color=/"red/"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";   
  50.   
  51.     }   
  52.     protected void AspNetPager1_PageChanged(object sender, EventArgs e)   
  53.     {   
  54.            //   
  55.         //AspNetPager1.CurrentPageIndex = ((Wuqi.Webdiyer.PageChangedEventArgs)e).NewPageIndex;   
  56.         BindData();    
  57.   
  58.     }   
  59. }   
發佈了23 篇原創文章 · 獲贊 4 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章