在VS2005下使用Webdiyer:AspNetPager完美实现多种样式分页

 


<%@ 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. }   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值