//Page
<% @ Register TagPrefix ="dnn" Namespace ="DotNetNuke.UI.WebControls" Assembly ="DotNetNuke" %>
< dnn : PagingControl ID ="ctlPagingControl" Width ="100%" runat ="server"></ dnn : PagingControl >
//Code:
// 分頁控件
DataTable splist= msmcontr.GetSProductsdt(PortalId);
if (splist.Rows.Count > 0)
{
ctlPagingControl.Visible = true ;
// 對PagedDataSource 對象的相關屬性指派
PagedDataSource objPds = new PagedDataSource ();
objPds.DataSource = splist.DefaultView;
objPds.AllowPaging = true ;
int CurPage = 1;
if (Request["currentpage" ] != null )
{
CurPage = int .Parse(Request["currentpage" ]);
}
int i = 0;
if (list.Count % _pagesize != 0)
{
i = (list.Count / _pagesize) + 1;
}
else
{
i = list.Count / _pagesize;
}
if (i < curPage)
{
curPage = 1;
}
objPds.CurrentPageIndex = CurPage - 1;
string reurl = Request.Url.ToString().ToLower();
Regex regex = new Regex("¤tpage=" + Request["currentpage"], RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
reurl = regex.Replace(reurl, "");
if(reurl.IndexOf("&language") > 0 && reurl.IndexOf(".aspx") > 0 )
reurl = reurl.Remove( reurl.IndexOf("&language") ,reurl.IndexOf(".aspx") + 4);
string para = reurl.Remove(0, reurl.IndexOf("?" ) + 1);
if (Request["tabid" ] != null )
{
para = para.ToLower().Replace("tabid=" + Request["tabid" ], "" );
}
ctlPagingControl.TotalRecords = splist.Rows.Count;
ctlPagingControl.PageSize = 5;
ctlPagingControl.CurrentPage = CurPage;
objPds.PageSize = 5;
ctlPagingControl.QuerystringParams = para;
ctlPagingControl.TabID = TabId;
// 把PagedDataSource 對象賦給Repeater 控件
dlProduct.DataSource = objPds;
dlProduct.RepeatColumns = 3;
dlProduct.RepeatDirection = RepeatDirection .Horizontal;
dlProduct.DataBind();
}
else
{
ctlPagingControl.Visible = false ;
}