ASP. NET paging control using "attached instance download"

Source: Internet
Author: User

This article mainly introduces the method of ASP. NET create transaction, it has good reference value, need friends to see it together

I. Description

AspNetPager.dll This paging control is primarily used for the ASP. NET WebForm Web site and will now collate the code as follows

Second, the Code

1. First add a reference to the test page Default.aspx page

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

2. Write a repeater list control to display the data

?
12345678 <asp:Repeater ID="rptNews" runat="server">  <ItemTemplate>    <li>      <span><%# Eval("time") %></span>      <a href="NewsShow.aspx?id=<%# Eval("id") %>"><%# Access.GetStringNum( Eval("name").ToString(),15) %></a>    </li>  </ItemTemplate></asp:Repeater>

3. Add

?
123456 <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" CustomInfoStyle="FONT-SIZE: 12px" FirstPageText="首页" HorizontalAlign="Center" inputboxstyle="width:19px" LastPageText="尾页" meta:resourcekey="AspNetPager1" NextPageText="下一页" PageSize="10" PrevPageText="上一页" Style="font-size: 14px" Width="95%" CssClass="anpager" CurrentPageButtonClass="cpb" OnPageChanging="AspNetPager1_PageChanging" ShowBoxThreshold="10"></webdiyer:AspNetPager> 

The PageSize property is used to set the number of displays per page

4. Background code Binding

Access is the test database access class, available in the final demo

5, pagination control Click on the page number event

?
123456 //分页protectedvoid AspNetPager1_PageChanging(objectsrc, Wuqi.Webdiyer.PageChangingEventArgs e){  this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;  ShowNews();}

Finally, the full page of code:

Default.aspx

?
1234567891011121314151617181920212223242526272829303132333435 <%@ 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"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>asp.net分页控件</title> <link href="css/css.css" rel="stylesheet" type="text/css" /> <style type="text/css"> .aboutcontentnr{width:100%; height:auto; } </style></head><body> <form id="form1" runat="server"> <div> <ul class="news"> <asp:Repeater ID="rptNews" runat="server"> <ItemTemplate>  <li><span>  <%# Eval("time") %></span><a href="NewsShow.aspx?id=<%# Eval("id") %>"><%# Access.GetStringNum( Eval("name").ToString(),15) %></a></li> </ItemTemplate> </asp:Repeater> </ul> <div class="paginator"> <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" CustomInfoStyle="FONT-SIZE: 12px" FirstPageText="首页" HorizontalAlign="Center" inputboxstyle="width:19px" LastPageText="尾页" meta:resourcekey="AspNetPager1" NextPageText="下一页" PageSize="10" PrevPageText="上一页" Style="font-size: 14px" Width="95%" CssClass="anpager" CurrentPageButtonClass="cpb" OnPageChanging="AspNetPager1_PageChanging" ShowBoxThreshold="10"> </webdiyer:AspNetPager> </div> </div> </form></body></html>

Default.aspx.cs

?
12345678910111213141516171819202122232425262728293031 using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;public partial class Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ShowNews(); } } //测试数据源 private void ShowNews() { String strSql = String.Format("select * from News order by time asc"); DataTable dtbl = Access.ExecuteDataTable(strSql, null); this.rptNews.DataSource = Access.GetPageDataSource(AspNetPager1, AspNetPager1.CurrentPageIndex - 1, dtbl); this.rptNews.DataBind(); } //分页点击页码事件 protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { this.AspNetPager1.CurrentPageIndex = e.NewPageIndex; ShowNews(); }}

Third, Demo

Aspnetpager (DLL)

Aspnetpage (Demo)

The above is the whole content of this article, I hope that the content of this article on everyone's study or work can bring some help, but also hope that a lot of support script home!

Original link: http://www.cnblogs.com/lengzhan/p/6054583.html

ASP. NET paging control using "attached instance download"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.