欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Repeater控件與PagedDataSource結(jié)合實(shí)現(xiàn)分頁功能

 更新時間:2014年01月02日 16:29:59   作者:  
Repeater控件與PagedDataSource相結(jié)合實(shí)現(xiàn)其分頁功能,如果控件開發(fā)人員需對自定義數(shù)據(jù)綁定控件提供分頁支持,即可使用此類

本文講解Repeater控件與PagedDataSource相結(jié)合實(shí)現(xiàn)其分頁功能。PagedDataSource 類封裝那些允許數(shù)據(jù)源控件(如 DataGrid、GridView)執(zhí)行分頁操作的屬性。如果控件開發(fā)人員需對自定義數(shù)據(jù)綁定控件提供分頁支持,即可使用此類。

PagedDataSource 類的部分公共屬性:

AllowCustomPaging // 獲取或設(shè)置指示是否啟用自定義分頁的值。 AllowPaging // 獲取或設(shè)置指示是否啟用分頁的值。 Count // 獲取要從數(shù)據(jù)源使用的項(xiàng)數(shù)。 CurrentPageIndex // 獲取或設(shè)置當(dāng)前頁的索引。 DataSource // 獲取或設(shè)置數(shù)據(jù)源。 DataSourceCount // 獲取數(shù)據(jù)源中的項(xiàng)數(shù)。 FirstIndexInPage // 獲取頁中的第一個索引。 IsCustomPagingEnabled // 獲取一個值,該值指示是否啟用自定義分頁。 IsFirstPage // 獲取一個值,該值指示當(dāng)前頁是否是首頁。 IsLastPage // 獲取一個值,該值指示當(dāng)前頁是否是最后一頁。 IsPagingEnabled // 獲取一個值,該值指示是否啟用分頁。 IsReadOnly // 獲取一個值,該值指示數(shù)據(jù)源是否是只讀的。 IsSynchronized // 獲取一個值,該值指示是否同步對數(shù)據(jù)源的訪問(線程安全)。 PageCount // 獲取顯示數(shù)據(jù)源中的所有項(xiàng)所需要的總頁數(shù)。 PageSize // 獲取或設(shè)置要在單頁上顯示的項(xiàng)數(shù)。 VirtualCount // 獲取或設(shè)置在使用自定義分頁時數(shù)據(jù)源中的實(shí)際項(xiàng)數(shù)。
下面是PagedDataSource類實(shí)現(xiàn)Repeater控件的分頁顯示例子,如圖:

復(fù)制代碼 代碼如下:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int pageIndex = 1;
try
{
pageIndex = Convert.ToInt32(Request.QueryString["Page"]);
if (pageIndex <= 0) pageIndex = 1;
}
catch
{
pageIndex = 1;
}
DataTable dt = GetDocumentTable();
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt.DefaultView; // 設(shè)置數(shù)據(jù)源
pds.AllowPaging = true; // 設(shè)置指示是否啟用分頁的值
pds.PageSize = 5; // 設(shè)置要在每頁顯示的數(shù)量
pds.CurrentPageIndex = pageIndex - 1; // 設(shè)置當(dāng)前頁的索引。
rptDocumentList.DataSource = pds;
rptDocumentList.DataBind();
ltlPageBar.Text = GetPageBar(pds);
}
}
// 分頁條
private string GetPageBar(PagedDataSource pds)
{
string pageBar = string.Empty;
int currentPageIndex = pds.CurrentPageIndex + 1;
if (currentPageIndex == 1)
{
pageBar += "首頁";
}
else
{
pageBar += " + Request.CurrentExecutionFilePath + "?Page=1">首頁";
}
if ((currentPageIndex - 1) < 1)
{
pageBar += "上一頁";
}
else
{
pageBar += " + Request.CurrentExecutionFilePath + "?Page=" + (currentPageIndex - 1) + "">上一頁";
}
if ((currentPageIndex + 1) > pds.PageCount)
{
pageBar += "下一頁";
}
else
{
pageBar += " + Request.CurrentExecutionFilePath + "?Page=" + (currentPageIndex + 1) + "">下一頁";
}
if (currentPageIndex == pds.PageCount)
{
pageBar += "末頁";
}
else
{
pageBar += " + Request.CurrentExecutionFilePath + "?Page=" + pds.PageCount + "">末頁";
}
return pageBar;
}
// 創(chuàng)建測試表
DataTable GetDocumentTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("DocumentId", typeof(int));
dt.Columns.Add("Title", typeof(string));
for (int i = 1; i <= 30; i++)
{
DataRow row = dt.NewRow();
row["DocumentId"] = i;
row["Title"] = "文檔標(biāo)題 " + i + "";
dt.Rows.Add(row);
}
return dt;
}

相關(guān)文章

最新評論