Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 12th, 2007, 12:10 PM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default datalist paging problem

Hi,
I have the following code
I got it from asp.net tutorials
but waht is the code for pagedData.DataSource=???
can you write an example to get some data from a database
in this code it is written products.Rows and getProducts() function
can you write the code
the code in that example is very complicated
i just need to page data in the datalist

 Public Function GetProductsAsPagedDataSource(ByVal pageIndex As Integer, ByVal pageSize As Integer) As PagedDataSource
        ' Get ALL of the products
        Dim products As Northwind.ProductsDataTable = GetProducts()

        ' Limit the results through a PagedDataSource
        Dim pagedData As New PagedDataSource()
        pagedData.DataSource = products.Rows
        pagedData.AllowPaging = True
        pagedData.CurrentPageIndex = pageIndex
        pagedData.PageSize = pageSize

        Return pagedData
    End Function

 Protected Sub FirstPage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FirstPage.Click
        ' Send the user to the first page
        RedirectUser(0)
    End Sub

    Protected Sub PrevPage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PrevPage.Click
        ' Send the user to the previous page
        RedirectUser(PageIndex - 1)
    End Sub

    Protected Sub NextPage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NextPage.Click
        ' Send the user to the next page
        RedirectUser(PageIndex + 1)
    End Sub

    Protected Sub LastPage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LastPage.Click
        ' Send the user to the last page
        RedirectUser(PageCount - 1)
    End Sub

    Private Sub RedirectUser(ByVal sendUserToPageIndex As Integer)
        ' Send the user to the requested page
        Response.Redirect(String.Format("Paging.aspx?pageI ndex={0}&pageSize={1}", sendUserToPageIndex, PageSize))
    End Sub

    Protected Sub ProductsDefaultPagingDataSource_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEv entArgs) Handles ProductsDefaultPagingDataSource.Selected
        ' Reference the PagedDataSource bound to the DataList
        Dim pagedData As PagedDataSource = CType(e.ReturnValue, PagedDataSource)

        ' Remember the total number of records being paged through across postbacks
        TotalRowCount = pagedData.DataSourceCount

        ' Configure the paging interface based on the data in the PagedDataSource
        FirstPage.Enabled = Not pagedData.IsFirstPage
        PrevPage.Enabled = Not pagedData.IsFirstPage
        NextPage.Enabled = Not pagedData.IsLastPage
        LastPage.Enabled = Not pagedData.IsLastPage

        ' Display the current page being viewed...
        CurrentPageNumber.Text = String.Format("You are viewing page {0} of {1}...", PageIndex + 1, PageCount)
    End Sub

#Region "Page-Level, Paging-Related properties"
    Private Property TotalRowCount() As Integer
        Get
            Dim o As Object = ViewState("TotalRowCount")
            If (o Is Nothing) Then
                Return -1
            Else
                Return Convert.ToInt32(o)
            End If
        End Get
        Set(ByVal Value As Integer)
            ViewState("TotalRowCount") = Value
        End Set
    End Property

    Private ReadOnly Property PageCount() As Integer
        Get
            If TotalRowCount <= 0 OrElse PageSize <= 0 Then
                Return 1
            Else
                Return ((TotalRowCount + PageSize) - 1) / PageSize
            End If
        End Get
    End Property

    Private ReadOnly Property PageIndex() As Integer
        Get
            If (Not String.IsNullOrEmpty(Request.QueryString("pageInde x"))) Then
                Return Convert.ToInt32(Request.QueryString("pageIndex"))
            Else
                Return 0
            End If
        End Get
    End Property

    Private ReadOnly Property PageSize() As Integer
        Get
            If (Not String.IsNullOrEmpty(Request.QueryString("pageSize "))) Then
                Return Convert.ToInt32(Request.QueryString("pageSize"))
            Else
                Return 4
            End If
        End Get
    End Property

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datalist with paging venkatu2005 ASP.NET 1.0 and 1.1 Professional 1 July 17th, 2008 01:10 AM
paging datalist shanwaj ASP.NET 2.0 Basics 1 March 25th, 2008 12:03 AM
Datalist Paging nedo_786 ASP.NET 2.0 Professional 9 September 20th, 2007 04:32 AM
How to allow paging in datalist? okboy SQL Server 2005 1 January 21st, 2007 10:08 PM
Datalist Paging in C# caitydev ASP.NET 2.0 Basics 0 March 29th, 2006 06:53 AM



All times are GMT -4. The time now is 12:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.