So_CooL的专栏

VS.NET源代碼

ASPNetPage分页

vs2005下使用ASPNetPage分页的例子1
页面设计
<%@ 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">
     <title>无标题页</title>
</head>
<body>
     <form id="form1" runat="server">
     <div>
         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
         <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
         <asp:GridView ID="GridView1" runat="server">
         </asp:GridView>
         <webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="1" OnPageChanged="AspNetPager1_PageChanged" OnPageChanging="AspNetPager1_PageChanging">
         </webdiyer:AspNetPager>
     </div>
     </form>
</body>
</html>

CodeBehide

protected void Page_Load(object sender, EventArgs e)
     {
         if (!Page.IsPostBack)
             GetLog();
     }
private void GetLog()
     {

         string strsql;

         //统计总的记录数

         SqlConnection Conn = new SqlConnection();

         Conn.ConnectionString = @"server=localhost//PMSERVER;uid=;pwd=;database=test";
         try
         {
             MeetWeb.SqlDataBase a = new MeetWeb.SqlDataBase("server=localhost//PMSERVER;uid=sa;pwd=;database=test");
     

             strsql = " Select count(ID) from test";

             DataSet ds = new DataSet();

             SqlDataAdapter Adp = a.CreateAdapter(strsql);

             Adp.Fill(ds, "test"); this.AspNetPager1.RecordCount = System.Convert.ToInt32(ds.Tables[0].Rows[0][0]);

           
             Response.Write(ds.Tables[0].Rows[0][0]);
         }
         catch (Exception ex)
         {
             Response.Write(ex.ToString());
         }
BindData();
     }

     private void BindData()
     {

         string strsql;

         int RecordPage = (AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize;

        
    

         strsql = String.Format(" Select Top   {0} *   From test Where   Id Not in ( Select Top {1} Id From test   Order By ID Desc) Order By ID Desc", AspNetPager1.PageSize.ToString(), RecordPage.ToString());
         DataSet ds = new DataSet();
         MeetWeb.SqlDataBase a = new MeetWeb.SqlDataBase("server=;uid=;pwd=;database=test");
     
         SqlDataAdapter Adp =a.CreateAdapter(strsql);

         Adp.Fill(ds, "test");

         this.GridView1.DataSource = ds.Tables["test"];

         this.GridView1.DataBind();

         //动态设置用户自定义文本内容

         Adp.Dispose();

         AspNetPager1.CustomInfoHTML= "记录总数:<font color=/"blue/"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";

         AspNetPager1.CustomInfoHTML += " 总页数:<font color=/"blue/"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";

         AspNetPager1.CustomInfoHTML += " 当前页:<font color=/"red/"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";

     }

//注意这里 和vs2003有区别
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
     {
         AspNetPager1.CurrentPageIndex = e.NewPageIndex;

         BindData();

         System.Text.StringBuilder sb = new StringBuilder("<script Language=/"Javascript/"><!--/n");


         sb.Append("var el=document.all;");

         sb.Append(this.GridView1.ClientID);

         sb.Append(".scrollIntoView(true);");

         sb.Append("<");

         sb.Append("/");

         sb.Append("script>");

         if (!ClientScript.IsStartupScriptRegistered("scrollScript"))

             ClientScript.IsStartupScriptRegistered(sb.ToString());
     }
 
阅读更多
上一篇12个div逐个显示效果
下一篇圓角樣式
想对作者说点什么? 我来说一句

AspNetPage分页控件使用

2012年10月23日 4KB 下载

aspnetpage分页方法

2011年12月16日 61KB 下载

aspnetpage

2012年04月12日 36KB 下载

强悍的aspnetpage 分页后台代码

2010年04月14日 535B 下载

asp.net单个新闻分页

2008年03月14日 21KB 下载

aspnetpage分页控件

2013年04月01日 5KB 下载

没有更多推荐了,返回首页

关闭
关闭