一個比較通用的分頁控件,完整的設(shè)計時支持和比較流行的分頁模式(提供源碼下載)
這是我寫的一個分頁控件,功能如下:
1.支持設(shè)計時支持和兩種分頁模式,其中綜合分頁模式的效果如下:
普通分頁模式的效果如下:
2.完善的設(shè)計時支持,包括自動套用格式和設(shè)計時面板設(shè)置:
使用方法:
在aspx頁面中:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Cyclone.CustomPager.WebApplication._Default" %>
<%@ Register assembly="Cyclone.CustomPager.Pager" namespace="Cyclone.CustomPager.Pager" tagprefix="Cyclone" %>
<!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>
<link type="text/css" rel="stylesheet" href="style/comm.css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="false" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" PagerSettings-Visible="false"
Width="80%" height="35" DataKeyNames="ID">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle ForeColor="White" VerticalAlign="Top" BackColor="Transparent" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="序號">
<ItemTemplate>
<%# Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="用戶ID" />
<asp:BoundField DataField="UserName" HeaderText="用戶名" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="Address" HeaderText="地址" />
</Columns>
</asp:GridView>
</div>
<div>
<Cyclone:AspNetPager ID="AspNetPager1" runat="server" ButtonText="GO" EndPageText="末頁"
FirstPageText="首頁" NextPageText="下一頁" PageSize="15" PrePageText="上一頁" OnPageChanged="Page_Changed" Width="80%" PageMode=Normal BackColor="#FFE0C0" BorderColor="#FFC0C0" BorderStyle="Solid" BorderWidth="1px" ForeColor="#804040">
<ButtonStyle CssClass="btn1_mouseout" Width="30px" />
<TextBoxStyle Width="30px" CssClass="blue_rounded"/>
<LabelStyle ForeColor="Red" Font-Bold="True" />
</Cyclone:AspNetPager>
</div>
</form>
</body>
</html>
在后臺代碼中:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Cyclone.CustomPager.WebApplication
{
public partial class _Default : System.Web.UI.Page
{
private List<User> _data=new List<User>();
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.GetData();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
this.AspNetPager1.PageIndex = 1;
}
}
private void GetData()
{
for (int i = 0; i < 1000; i++)
{
this._data.Add(new User { ID = i + 1, Address = "北京市海淀區(qū)", Email = "mickjacksonfeng@163.com", UserName = "憑海觀瀾" });
}
}
protected void Page_Changed(object sender, EventArgs e)
{
BindData();
}
#region 綁定試卷定義方案列表
/// <summary>
/// 根據(jù)當(dāng)前頁碼查詢需要的數(shù)據(jù)
/// </summary>
/// <param name="pageIndex">頁碼</param>
private void BindData()
{
this.AspNetPager1.RecordCount = this._data.Count;
List<User> users = this._data.Skip(this.AspNetPager1.PageSize*(this.AspNetPager1.PageIndex-1)).Take(this.AspNetPager1.PageSize).ToList();
GridView1.DataSource = users;
GridView1.DataBind();
}
#endregion
}
public class User
{
public int ID { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public string Address { get; set; }
}
}
另外:
本分頁控件還包含簡單屬性,復(fù)雜屬性,自定義視圖狀態(tài),分頁事件,創(chuàng)建控件,render控件,Attribute,設(shè)計時支持等比較齊全的自定義控件的元素,是個不錯學(xué)習(xí)自定義控件開發(fā)的例子,詳細代碼可以到下面進行下載: 腳本之家下載地址
相關(guān)文章
MVC默認路由實現(xiàn)分頁(PagerExtend.dll下載)
這篇文章主要介紹了MVC默認路由實現(xiàn)分頁,采用bootstrap的樣式,文末提供了PagerExtend.dll下載地址,感興趣的小伙伴們可以參考一下2016-07-07ASP.NET動態(tài)設(shè)置頁面標(biāo)題的方法詳解
這篇文章介紹了ASP.NET動態(tài)設(shè)置頁面標(biāo)題的方法詳解,有需要的朋友可以參考一下2013-07-07asp.net使用jQuery獲取RadioButtonList成員選中內(nèi)容和值示例
這篇文章主要介紹了通過jQuery來獲取RadioButtonList成員內(nèi)容的方法,大家參考使用吧2014-01-01Entity?Framework根據(jù)實體的EntityState狀態(tài)實現(xiàn)增刪改查
這篇文章介紹了Entity?Framework根據(jù)實體的EntityState狀態(tài)實現(xiàn)增刪改查,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03asp.net Menu控件+SQLServer實現(xiàn)動態(tài)多級菜單
asp.net Menu控件+SQLServer實現(xiàn)動態(tài)多級菜單的代碼,需要的朋友可以參考下。2011-12-12ASP.net WebAPI跨域調(diào)用問題的解決方法
在做Web開發(fā)中,常常會遇到跨域的問題,到目前為止,已經(jīng)有非常多的跨域解決方案。下面這篇文章主要給大家介紹了關(guān)于ASP.net WebAPI跨域調(diào)用問題的解決方法,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下。2018-03-03