sciamannikoo
-
4/9/2005 12:27:18 PM
Re: Paging
I've use that to page a Datalist. With this code we can page all repeaters controls (repeater, datali, datagrid too).
I write a simple description, but with few modification we can page with number pages, intevarls, etc...
First, near repeater control, add two hyperlink controls, to move to previous (htPrev) and next (htNext) page, and a text box to show current page. I've added these controls in a panel control (pnlTop) to hide all if i've only one page.
Att these field: Public pagedData As New PagedDataSource
In Page_Load, add these two rows: doPaging() pnlTop.Visible = Not (GetDataSource() Is Nothing OrElse GetDataSource.Tables(0).Rows.Count = 0)
Function GetDataSource return some data (all records!!!)
This is the heart of paging:
Sub doPaging() Dim selectionid As String = Request.Params("selection")
Dim intPage As Int32 If Request.QueryString("Page") = "" Then intPage = 0 Else intPage = CType(Request.QueryString("Page"), Int32) End If
'we assing to pageddatasource full datasource pagedData.DataSource = GetDataSource.Tables(0).DefaultView 'we active pagine e set records number to show for each page pagedData.AllowPaging = True pagedData.PageSize = 10 i Try pagedData.CurrentPageIndex = intPage Catch ex As Exception pagedData.CurrentPageIndex = 0 End Try
'we show previous and next control hlTPrev.Visible = (Not pagedData.IsFirstPage) And pagedData.PageCount > 1 hlTNext.Visible = (Not pagedData.IsLastPage) And pagedData.PageCount > 1
'we show current URLs pattern Dim strPage As String = ResolveUrl(Functions.GetAliasPath) & "?Page={0}&selection={1}"
'we set buttons URLs hlTPrev.NavigateUrl = String.Format(strPage, (pagedData.CurrentPageIndex - 1), Request.Params("selection")) hlTNext.NavigateUrl = String.Format(strPage, (pagedData.CurrentPageIndex + 1), Request.Params("selection"))
'we get current page numer a count pageTNumber.Text = "Page " & (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount pageTNumber.Visible = (pagedData.PageCount > 1)
'we conntect datasource to control Me.CMSDataList2.DataSource = pagedData Me.CMSDataList2.DataBind() End Sub
Bye, Andrea
|