因為項目需要
下面實例是用PagedDataSource類實現DataList控件的數據分頁
頁面後台代碼
using System;
using System
using System
using System
using System
using System
using System
using System
using System
using System
using System
using System
public partial class Demo : System
{
protected SqlConnection conn; //添加數據庫的操作對象
protected SqlDataAdapter da;
protected DataSet ds;
protected SqlCommand comm;
protected void Page_Load(object sender
{
getArticle();
}
private void getArticle() //取得Article數據
{
conn = new SqlConnection(
da = new SqlDataAdapter();
da
ds = new DataSet();
try
{
conn
da
conn
}
catch (SqlException e
{
Response
}
int cup = Convert
PagedDataSource ps = new PagedDataSource();
ps
ps
ps
ps
lb_count
lb_page
if (!IsPostBack)
{
for (int i =
{
this
}
LinkUp
LinkDown
}
try
{
DropDownList
DataList
DataList
}
catch (Exception ex)
{
throw ex;
}
}
protected void LinkDown_Click(object sender
{
try
{
lb_CurrentPage
DropDownList
getArticle();
}
catch (Exception ex)
{
Response
lb_CurrentPage
getArticle();
}
}
protected void DropDownList
{
int page =Convert
lb_CurrentPage
getArticle();
}
protected void LinkUp_Click(object sender
{
try
{
if (Convert
{
lb_CurrentPage
DropDownList
getArticle();
}
else
{
Response
}
}
catch (Exception ex)
{
Response
}
}
protected void LinkFirst_Click(object sender
{
if (lb_CurrentPage
lb_CurrentPage
else
{
Response
}
getArticle();
}
protected void LinkLast_Click(object sender
{
if (lb_CurrentPage
lb_CurrentPage
else
{
Response
}
getArticle();
}
}
頁面前台代碼
<%@ Page Language=
<!DOCTYPE html PUBLIC
<html xmlns=
<head runat=
<title>無標題頁</title>
</head>
<body>
<form id=
<div>
<asp:DataList ID=
<ItemTemplate>
<asp:Label ID=
<asp:Label ID=
</ItemTemplate>
</asp:DataList></div>
<br />
共<asp:Label ID=
共<asp:Label ID=
當前第<asp:Label ID=
<asp:LinkButton ID=
<asp:LinkButton ID=
<asp:LinkButton ID=
<asp:LinkButton ID=
轉到第<asp:DropDownList ID=
</asp:DropDownList>頁
</form>
</body>
</html>
注: PagedDataSource 類的部分公共屬性
AllowCustomPaging 獲取或設置指示是否啟用自定義分頁的值
AllowPaging 獲取或設置指示是否啟用分頁的值
Count 獲取要從數據源使用的項數
CurrentPageIndex 獲取或設置當前頁的索引
DataSource 獲取或設置數據源
DataSourceCount 獲取數據源中的項數
FirstIndexInPage 獲取頁中的第一個索引
IsCustomPagingEnabled 獲取一個值
IsFirstPage 獲取一個值
IsLastPage 獲取一個值
IsPagingEnabled 獲取一個值
IsReadOnly 獲取一個值
IsSynchronized 獲取一個值
PageCount 獲取顯示數據源中的所有項所需要的總頁數
PageSize 獲取或設置要在單頁上顯示的項數
VirtualCount 獲取或設置在使用自定義分頁時數據源中的實際項數
From:http://tw.wingwit.com/Article/program/net/201311/12972.html