码迷,mamicode.com
首页 > 数据库 > 详细

C# - 杨涛分页控件AspNetPager sql分页篇

时间:2016-03-27 11:03:24      阅读:411      评论:0      收藏:0      [点我收藏+]

标签:

http://www.webdiyer.com/downloads/

 

前台

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

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></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,"id")%></td>
        <td><%#DataBinder.Eval(Container.DataItem,"year")%></td>
        <td><%#DataBinder.Eval(Container.DataItem,"month")%></td>
        <td><%#DataBinder.Eval(Container.DataItem,"day")%></td>
        </tr>
        </ItemTemplate>
        </asp:Repeater>
    </table>

<webdiyer:AspNetPager
           ID="AspNetPager1" 
           runat="server" 
           Width="100%" 
           NumericButtonCount="6" 
           UrlPaging="false" 
           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>

 

后台

 

using CY.CommonLibrary.Common;
using System;
using System.Collections.Generic;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    private SQLDBHelper db = new SQLDBHelper(System.Configuration.ConfigurationManager.AppSettings["connstr"]);

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

    protected void AspNetPager1_PageChanged(object src, EventArgs e)
    {
        BindGrid();
    }

    public void BindGrid()
    {

        int pageIndex = this.AspNetPager1.CurrentPageIndex - 1;
        int pageSize = this.AspNetPager1.PageSize = 20;

        string sql = @"
                        declare @count int
                        exec dbo.pagedemo 【pageIndex】,【pageSize】,@count output
                        select @count
                    ";

        sql = sql.FormatByKeywords
          (
                  new Dictionary<string, string>()
                            {
                                { "pageIndex", pageIndex.CheckData(CheckTypez.TransferSQL, "") },
                                { "pageSize", pageSize.CheckData(CheckTypez.TransferSQL, "") }
                            },
                  "", ""
          );

        DataSet ds = db.ExecuteDataSet(sql);

        this.AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToNotNullString());

        Repeater1.DataSource = ds.Tables[0];
        Repeater1.DataBind();
    }
}

 

C# - 杨涛分页控件AspNetPager sql分页篇

标签:

原文地址:http://www.cnblogs.com/CyLee/p/5325036.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!