Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Paging for DataList
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Paging for DataList

 Post Reply Post Reply Page  12>
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Paging for DataList
    Posted: 26 January 2005 at 1:28am
I need some help with the code for a datalist. I want to use paging for this datalist.
 
I got the following error message: Compiler Error Message: BC30456: 'CurrentPageIndex' is not a member of 'System.Web.UI.WebControls.DataList'.

Source Error:

Line 25:          
Line 26:                  'Get new paging index 
Line 27:                  dtlGBook.CurrentPageIndex = objArgs.NewPageIndex 
 
I know what this means. CurrentPageIndex is not a member of DataList. It's actually a member of DataGrid. What should I use instead for DataList?
 
Let me give the significiant parts of my code:
 
 
 Sub dtlGBook_PageChanger(objSender As Object, _ 
                & ;nbs p;                &a mp;n bsp;           objArgs As DataGridPageChangedEventArgs )
        
                 'Get new paging index
                 dtlGBook.CurrentPageIndex = objArgs.NewPageIndex

        
                 Call BindDataList()
        
        End Sub
        '---------------------------------------------
        ' name: BindDataList()
        '---------------------------------------------
        Sub BindDataList()
                 Dim strConnect As String
                 Dim objConnect As New OleDbConnection()
                 Dim objCommand As New OleDbCommand()
                 Dim strSQL as String
                 Dim dtaGBook As New OleDbDataAdapter()
                 Dim dtsGBook As New DataSet()
            Dim databaseName as String
            Dim path as String
        databaseName = ""
       
        'Create Connection object 
                
         
                 objConnect.ConnectionString = strConnect
                 objConnect.Open()
     
        'Build SQL string
        strSQL = "My SQL Statement"
 
                 'Set the Command Object properties
                 objCommand.Connection = objConnect
                 objCommand.CommandType = CommandType.Text
                 objCommand.CommandText = strSQL
 
                 'Create a new DataAdapter object
                 dtaGBook.SelectCommand = objCommand
 
                 'Get the data from the database and
                 'put it into a DataTable object named dttGBook in the DataSet object
                 dtaGBook.Fill(dtsGBook, "dttGBook")
 
                 'Set the DataSource property of the DataList 
                 dtlGBook.DataSource = dtsGBook
 
                 'Bind all the controls on the page
                 dtlGBook.DataBind()
        End Sub
 
Small parts of my code after <form runat="server"> :
   <asp:datalist id="dtlGBook" runat="server"
        width=600   
        AllowPaging="True"
         OnPageIndexChanged="dtlGBook_PageChanger"
         PagerStyle-Mode="NumericPages"
         Pagesize="5"
     
        enableviewstate=false>
 


Edited by Misty - 26 January 2005 at 1:30am
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 26 January 2005 at 2:21am
DataLists don't actually have built in paging, you have to implement it yourself. This may help you:


'For this function you just need to add a panel called pnlPager that will contain the pages, you also need to change the URL's that are built below

    Public Function GetPagedDataSource(ByVal DataSource As IEnumerable) As PagedDataSource
        Dim pds As New PagedDataSource

        pds.DataSource = DataSource
        pds.AllowPaging = True
        pds.PageSize = CInt(ddlItemsPerPage.SelectedItem.Value)
        Dim CPage As Integer = CInt(Request.QueryString("Page"))
        pds.CurrentPageIndex = CPage

        For i As Integer = 1 To pds.PageCount
            Dim pageLink As Object
            Dim spacer As New LiteralControl(" ")

            If (i - 1) = pds.CurrentPageIndex Then
                pageLink = New Label
            Else
                pageLink = New HyperLink
                If Request.QueryString("q") Is Nothing Then
                &n bsp;   pageLink.NavigateUrl = "default.aspx?FeedId=" & CInt(Request.QueryString("FeedId")) & "&Page=" & (i - 1)
                Else
                &n bsp;   pageLink.NavigateUrl = "default.aspx?q=" & Request.QueryString("q") & "&Page=" & (i - 1)
                End If
            End If

            pageLink.Text = i

            pnlPager.Controls.Add(pageLink)
            pnlPager.Controls.Add(spacer)
        Next

        Return pds
    End Function

'Then just

YourRepeater.DataSoruce = GetPagedDataSource(YourDataSet.Tables(0).DefaultView)


This code does work, as I wrote it for http://www.devjunkies.com/news


Edited by Mart - 26 January 2005 at 3:04am
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 27 January 2005 at 1:09am
Mart,
 
I tried finding the article that you wrote for http://www.devjunkies.com/news, but I could not find it. Can you please give me the exact URL?
 
I had a couple of problems when I tried to use your code.
 
1.) I got the following error message regarding pds.PageSize = CInt(ddlItemsPerPage.SelectedItem.Value) : Compiler Error Message: BC30451: Name 'ddlItemsPerPage' is not declared.

Source Error:

Line 24:         pds.DataSource = DataSource
Line 25:         pds.AllowPaging = True
Line 26:         pds.PageSize = CInt(ddlItemsPerPage.SelectedItem.Value)
 
2.) I added this line: dim ddlItemsPerPage, but I got the following error message: Exception Details: System.NullReferenceException: Object variable or With block variable not set.

Source Error:

Line 24:         pds.DataSource = DataSource
Line 25:         pds.AllowPaging = True
Line 26:         pds.PageSize = CInt(ddlItemsPerPage.SelectedItem.Value)
 
 3.) The same thing happened with pnlPager.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 27 January 2005 at 2:15am
I meant I used that code when building www.devjunkies.com/news so it does work.

You need to change line 26 from

       pds.PageSize = CInt(ddlItemsPerPage.SelectedItem.Value)

to something like

       pds.PageSize = 10
Depending on how many items you want to be shown on each page
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 27 January 2005 at 2:25am

That solved the problem with the PageSize. I am still having problems with pnlPager. I tried doing this: dim pnlPager. It would not work. How do I solve this problem? You can find the error message that I got below.

Compiler Error Message: BC30451: Name 'pnlPager' is not declared.

Source Error:

Line 48:             pageLink.Text = i
Line 49: 
Line 50:             pnlPager.Controls.Add(pageLink)
Line 51:             pnlPager.Controls.Add(spacer)


Edited by Misty - 27 January 2005 at 2:25am
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 27 January 2005 at 9:42am
pnlPager is a Panel Control that Mart added below the datalist, in that panel the pager controls are located.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 27 January 2005 at 11:13am
You need to follow the instructions I put in the comment before the function:

'For this function you just need to add a panel called pnlPager that
will contain the pages, you also need to change the URL's that are used in the function

Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 27 January 2005 at 1:00pm
I had already changed the name of the web pages from default.aspx to my own web page.
 
I added the following line of code: <asp:label id="pnlPager" runat="server" Font-Names="Verdana" Font-Size="12px"/>  at the bottom of the DataList. This solved the problem. Thank you for sharing the code with me!
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.