效果图片:
显示页面的Html代码:
 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="AspNetPager.aspx.cs" Inherits="AspNetPager" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AspNetPager.aspx.cs" Inherits="AspNetPager" %>
 <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<%@ 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">
<!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" >
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">
<head runat="server"> <title>无标题页</title>
    <title>无标题页</title> </head>
</head> <body>
<body> <form id="form1" runat="server">
    <form id="form1" runat="server"> <div style="text-align: center">
    <div style="text-align: center"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" /><br />
        <asp:Button ID="Button1" runat="server" Text="Button" /><br /> <div style="width: 100px; height: 448px">
        <div style="width: 100px; height: 448px"> <asp:GridView ID="GridView1" runat="server" Width="664px" Height="64px" OnRowDataBound="GridView1_RowDataBound">
        <asp:GridView ID="GridView1" runat="server" Width="664px" Height="64px" OnRowDataBound="GridView1_RowDataBound"> </asp:GridView>
        </asp:GridView> </div>
        </div> <br />
        <br /> <asp:Label ID="CustomInfoClass" runat="server"></asp:Label><br />
        <asp:Label ID="CustomInfoClass" runat="server"></asp:Label><br /> <webdiyer:AspNetPager ID="AspNetPager1" runat="server" UrlPaging="true"
        <webdiyer:AspNetPager ID="AspNetPager1" runat="server" UrlPaging="true"  PageSize="10" ShowCustomInfoSection="Left" NumericButtonTextFormatString="[{0}]"
        PageSize="10" ShowCustomInfoSection="Left" NumericButtonTextFormatString="[{0}]"  AlwaysShow="true" OnPageChanged="AspNetPager1_PageChanged" Width="296px" CustomInfoSectionWidth="60%" ShowInputBox="Never" TextAfterInputBox="" TextBeforeInputBox="" >
         AlwaysShow="true" OnPageChanged="AspNetPager1_PageChanged" Width="296px" CustomInfoSectionWidth="60%" ShowInputBox="Never" TextAfterInputBox="" TextBeforeInputBox="" > </webdiyer:AspNetPager>
        </webdiyer:AspNetPager> 
     </div>
    </div> </form>
    </form> </body>
</body> </html>
</html> 
显示页面的CS代码:
 using System;
using System; using System.Data;
using System.Data; using System.Configuration;
using System.Configuration; using System.Collections;
using System.Collections; using System.Web;
using System.Web; using System.Web.Security;
using System.Web.Security; using System.Web.UI;
using System.Web.UI; using System.Web.UI.WebControls;
using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
using System.Web.UI.HtmlControls; using System.Data.SqlClient;
using System.Data.SqlClient; using System.Text;
using System.Text;
 public partial class AspNetPager : System.Web.UI.Page
public partial class AspNetPager : System.Web.UI.Page {
{ protected void Page_Load(object sender, EventArgs e)
    protected void Page_Load(object sender, EventArgs e) {
    { if (!this.IsPostBack)
        if (!this.IsPostBack) {
        { getLog();
            getLog(); }
        } }
    }
 private void getLog()
    private void getLog() {
    { string con = ConfigurationManager.ConnectionStrings["AspNetPagerConnectionString"].ConnectionString;
        string con = ConfigurationManager.ConnectionStrings["AspNetPagerConnectionString"].ConnectionString; SqlConnection dbconnection = new SqlConnection(con);
        SqlConnection dbconnection = new SqlConnection(con); try
        try {
        { SqlCommand cmd = new SqlCommand("select count(newsid) from wqnews", dbconnection);
            SqlCommand cmd = new SqlCommand("select count(newsid) from wqnews", dbconnection); SqlDataAdapter sda = new SqlDataAdapter(cmd);
            SqlDataAdapter sda = new SqlDataAdapter(cmd); //wqnews可以是别名
            //wqnews可以是别名 DataSet ds = new DataSet("wqnews");
            DataSet ds = new DataSet("wqnews"); sda.Fill(ds, "wqnews");
            sda.Fill(ds, "wqnews"); this.AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            this.AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]); Response.Write(ds.Tables[0].Rows[0][0]);
            Response.Write(ds.Tables[0].Rows[0][0]); }
        } catch (Exception e)
        catch (Exception e) {
        { Response.Write(e.Message);
            Response.Write(e.Message); }
        } BindData();
        BindData(); }
    }
 private void BindData()
    private void BindData() {
    { string con = ConfigurationManager.ConnectionStrings["AspNetPagerConnectionString"].ConnectionString;
        string con = ConfigurationManager.ConnectionStrings["AspNetPagerConnectionString"].ConnectionString; SqlConnection dbconnection = new SqlConnection(con);
        SqlConnection dbconnection = new SqlConnection(con);
 int RecordPage = (AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize;
        int RecordPage = (AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize; //string strsql =string.Format("select * from wqnews order by addtime desc",AspNetPager1.PageSize.ToString(),RecordPage.ToString());
        //string strsql =string.Format("select * from wqnews order by addtime desc",AspNetPager1.PageSize.ToString(),RecordPage.ToString()); SqlCommand cmd=new SqlCommand("select * from wqnews order by addtime desc",dbconnection);
        SqlCommand cmd=new SqlCommand("select * from wqnews order by addtime desc",dbconnection); DataSet ds= new DataSet();
        DataSet ds= new DataSet(); SqlDataAdapter sda = new SqlDataAdapter(cmd);
        SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(ds, RecordPage,AspNetPager1.PageSize, "wqnews");
        sda.Fill(ds, RecordPage,AspNetPager1.PageSize, "wqnews"); this.GridView1.DataSource = ds.Tables[0];
        this.GridView1.DataSource = ds.Tables[0]; this.GridView1.DataBind();
        this.GridView1.DataBind();
 //动态设置用户自定义文本内容
        //动态设置用户自定义文本内容 sda.Dispose();
        sda.Dispose(); AspNetPager1.CustomInfoClass = "记录总数:<font color=\"blue\"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
        AspNetPager1.CustomInfoClass = "记录总数:<font color=\"blue\"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>"; AspNetPager1.CustomInfoClass += "总页数:<font color=\"blue\"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
        AspNetPager1.CustomInfoClass += "总页数:<font color=\"blue\"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>"; AspNetPager1.CustomInfoClass += "当前页:<font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
        AspNetPager1.CustomInfoClass += "当前页:<font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>"; CustomInfoClass.Text = AspNetPager1.CustomInfoClass;
        CustomInfoClass.Text = AspNetPager1.CustomInfoClass; }
    }
 protected void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
    protected void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e) {
    { this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        this.AspNetPager1.CurrentPageIndex = e.NewPageIndex; BindData();
        BindData(); StringBuilder sb = new StringBuilder("<script Language=\"Javascript\"><!--\n");
        StringBuilder sb = new StringBuilder("<script Language=\"Javascript\"><!--\n");
 sb.Append("var el=document.all;");
        sb.Append("var el=document.all;");
 sb.Append(this.GridView1.ClientID);
        sb.Append(this.GridView1.ClientID);
 sb.Append(".scrollIntoView(true);");
        sb.Append(".scrollIntoView(true);");
 sb.Append("<");
        sb.Append("<");
 sb.Append("/");
        sb.Append("/");
 sb.Append("script>");
        sb.Append("script>");
 if (!ClientScript.IsStartupScriptRegistered("scrollScript"))
        if (!ClientScript.IsStartupScriptRegistered("scrollScript")) {
        { ClientScript.IsStartupScriptRegistered(sb.ToString());
            ClientScript.IsStartupScriptRegistered(sb.ToString()); }
        }
 }
    } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
    { if (e.Row.RowType == DataControlRowType.DataRow)
        if (e.Row.RowType == DataControlRowType.DataRow) {
        { e.Row.Attributes.Add("onMouseOver", "c=this.style.backgroundColor;this.style.backgroundColor='eafae9';");
            e.Row.Attributes.Add("onMouseOver", "c=this.style.backgroundColor;this.style.backgroundColor='eafae9';"); e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=c;");
            e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=c;"); }
        } }
    } }
}  
                     
                    
                 
                    
                 


 
     
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号