AspNetPager+GridView實現(xiàn)分頁的實例代碼
.框架是.NET Framework 4.0
.一共為三個部分: 前臺頁面設(shè)計代碼、前臺頁面程序代碼、css樣式
.其中數(shù)據(jù)庫連接操作用了DB類(連接語句),SQLHelper(微軟的數(shù)據(jù)庫操作類)
效果圖:
前臺頁面設(shè)計代碼
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestWebSite.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>
<link href="Styles/Paging.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" Height="261px" Width="737px"
CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle HorizontalAlign="Left" BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</div>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server"
onpagechanged="AspNetPager1_PageChanged" CssClass="anpager"
CurrentPageButtonClass="cpb" FirstPageText="首頁" LastPageText="尾頁"
NextPageText="后頁" PrevPageText="前頁">
</webdiyer:AspNetPager>
</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 TestWebSite.Utilities;
using System.Data;
using System.Data.SqlClient;
using Wuqi.Webdiyer;
namespace TestWebSite
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//調(diào)用綁定分頁和GridView
BindGridView();
}
}
////綁定分頁和GridView方法
private void BindGridView()
{
//查詢語句
string sequal = "select StandardName as 標準名稱, MakeUpItem as 補償項目, Unit as 單位,"
+ " cast(UnitPrice as decimal(18,2)) as 單價, cast(StandRate as decimal(18,2)) as "
+ "成新率, Type as 分類 from Standard";
//獲取數(shù)據(jù)表格
DataTable dt =
SqlHelper.ExecuteDataset(DB.con, CommandType.Text, sequal).Tables[0];
//初始化分頁數(shù)據(jù)源實例
PagedDataSource pds = new PagedDataSource();
//設(shè)置總行數(shù)
AspNetPager1.RecordCount = dt.Rows.Count;
//設(shè)置分頁的數(shù)據(jù)源
pds.DataSource = dt.DefaultView;
//設(shè)置當前頁
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
//設(shè)置每頁顯示頁數(shù)
pds.PageSize = AspNetPager1.PageSize;
//啟用分頁
pds.AllowPaging = true;
//設(shè)置GridView的數(shù)據(jù)源為分頁數(shù)據(jù)源
GridView1.DataSource = pds;
//綁定GridView
GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
//調(diào)用綁定分頁和GridView
BindGridView();
}
}
}
CSS樣式
.anpager
{
font: 11px Arial, Helvetica, sans-serif;
padding:10px 20px 10px 0;
margin: 0px;
}
.anpager a
{
padding: 1px 6px;
border: solid 1px #ddd;
background: #fff;
text-decoration: none;
margin-right:2px
}
.anpager a:visited
{
padding: 1px 6px;
border: solid 1px #ddd;
background: #fff;
text-decoration: none;
}
.anpager .cpb
{
padding: 1px 6px;
font-weight: bold;
font-size: 13px;
border:none
}
.anpager a:hover
{
color: #fff;
background: #ffa501;
border-color:#ffa501;
text-decoration: none;
}
/* AspNetPager1屬性設(shè)置: CssClass="anpager" CurrentPageButtonClass="cpb"*/
- asp.net gridview分頁:第一頁 下一頁 1 2 3 4 上一頁 最末頁
- asp.net中的GridView分頁問題
- Android入門之ActivityGroup+GridView實現(xiàn)Tab分頁標簽的方法
- GridView分頁的實現(xiàn)以及自定義分頁樣式功能實例
- Android中實現(xiàn)多行、水平滾動的分頁的Gridview實例源碼
- Asp.net GridView使用大全(分頁實現(xiàn))
- GridView分頁的實現(xiàn)(通用分頁模板)
- asp.net中g(shù)ridview的查詢、分頁、編輯更新、刪除的實例代碼
- GridView高效分頁和搜索功能的實現(xiàn)代碼
- 解析GridView自帶分頁及與DropDownList結(jié)合使用
相關(guān)文章
ASP.net Substitution 頁面緩存而部分不緩存的實現(xiàn)方法
在ASP.NET中要實現(xiàn)部分內(nèi)容非緩存,而其它的都需要緩存輸出,可以使用Substitution控件實現(xiàn).2009-03-03asp.net DataGrid 中文字符排序的實現(xiàn)代碼
在論壇上看到有位朋友希望對中文按拼音進行排序,剛好最近有點空,貼一份原來一個同事寫的一個排序類,僅稍微改動了下下,拿出來分享下.2009-09-09.net core2.0下使用Identity改用dapper存儲數(shù)據(jù)(實例講解)
下面小編就為大家分享一篇.net core2.0下使用Identity改用dapper存儲數(shù)據(jù)的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-11-11asp.net網(wǎng)站首頁根據(jù)IP自動跳轉(zhuǎn)指定頁面的示例
本文介紹的程序主要實現(xiàn)根據(jù)IP地址或地址段或IP所在城市進行自動跳轉(zhuǎn)到指定頁面的功能,需要的朋友可以參考下2014-02-02ScriptManager.RegisterStartupScript()方法在ajax頁面無效的解決方法
ScriptManager.RegisterStartupScript()方法在ajax頁面無效的解決方法2010-03-03ASP.NET Core使用JWT自定義角色并實現(xiàn)策略授權(quán)需要的接口
這篇文章介紹了ASP.NET Core使用JWT自定義角色并實現(xiàn)策略授權(quán)需要的接口,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-01-01asp.net+Ligerui實現(xiàn)grid導(dǎo)出Excel和Word的方法
這篇文章主要介紹了asp.net+Ligerui實現(xiàn)grid導(dǎo)出Excel和Word的方法,實例分析了asp.net結(jié)合jQuery的Ligerui插件操作excel和word文件的技巧,需要的朋友可以參考下2016-04-04