码迷,mamicode.com
首页 > Web开发 > 详细

.net分页控件webdiyer:AspNetPager

时间:2017-02-10 14:37:13      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:register   分页   控件   index   prot   void   spn   ges   box   

首先下载:AspNetPager.dll   AspNetPager.xml  放到bin目录下
页面添加<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

1  <webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged"
2        FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" ShowPageIndexBox="Never"
3         AlwaysShow="true" UrlPaging="True" ReverseUrlPageIndex="True">
4  </webdiyer:AspNetPager>

cs代码中:

 1 DataTable dt = new DataTable();
 2 PagedDataSource pds = new PagedDataSource();
 3 
 4 protected void Page_Load(object sender, EventArgs e)
 5     {
 6             dt = .......;
 7             pds.DataSource = dt.DefaultView;
 8             pds.AllowPaging = true;
 9             pds.PageSize = 10;
10             AspNetPager1.RecordCount = pds.Count;
11             AspNetPager1.PageSize = pds.PageSize;
12             if (!IsPostBack)
13             {
14                 Repeater1.DataSource = pds;
15                 Repeater1.DataBind();
16             }
17         }
18     }
19 
20     protected void AspNetPager1_PageChanged(object sender, EventArgs e)
21     {
22         pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;//索引同步
23         Repeater1.DataSource = pds;//数据绑定
24         Repeater1.DataBind();
25     }

这样分页显示没问题了,但要是页面中有检索条件,需要重新给datatable赋值的话,点翻页就会出问题了。比如检索出的数据有5页,而page_load中加载的datatable有10页。

点击检索按钮检索出需要的数据后,再翻页又变成全部数据了。下边解决。

 1 DataTable dt = new DataTable();
 2     PagedDataSource pds = new PagedDataSource();
 3     static DataView view = new DataView();
 4     protected void Page_Load(object sender, EventArgs e)
 5     {
 6         dt = .....;
 7         if (Request.QueryString["page"] == null)
 8         {
 9             view = dt.DefaultView;                   
10         }
11         if (!IsPostBack)
12         {
13             pds.DataSource = view;
14             AspNetPager1.RecordCount = view.Count;
15             pds.AllowPaging = true;
16             pds.PageSize = 5;
17             AspNetPager1.PageSize = pds.PageSize;
18             Repeater1.DataSource = pds;
19             Repeater1.DataBind();
20         }
21     }
22     protected void AspNetPager1_PageChanged(object sender, EventArgs e)
23     {
24         pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;//索引同步
25         Repeater1.DataSource = pds;//数据绑定
26         Repeater1.DataBind();
27     }
28     //按条件检索
29     protected void Button1_Click(object sender, EventArgs e)
30     {
31         //button1  根据订单编号和订单时间搜索
32         string ddh = TextBox1.Text.Replace(" ", "");
33         string startDt = TxtStartTime.Value;
34         string endDt = TxtEndTime.Value;
35         dt = 新table;
36         view = dt.DefaultView;
37         pds.DataSource = view;
38         AspNetPager1.RecordCount = view.Count;
39         pds.AllowPaging = true;
40         pds.PageSize = 5;
41         AspNetPager1.PageSize = pds.PageSize;
42         Repeater1.DataSource = pds;
43         Repeater1.DataBind();
44     }

 

.net分页控件webdiyer:AspNetPager

标签:register   分页   控件   index   prot   void   spn   ges   box   

原文地址:http://www.cnblogs.com/zk-zhou/p/6386016.html

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