DataList pagination

Posted on 2008-10-11
Last Modified: 2012-05-05
I need to add a pagination to a datalist control
here is my code

<asp:DataList ID="ProductDataList" RepeatColumns="2"  runat="server" >
                            <div style="margin:10px; width:50%;">
                                <div style="float:left; margin-right:5px;">
                                    <asp:Image ID="imgProduct" runat="server" ImageUrl='<%# Eval("img") %>' CssClass="catImg" BorderStyle="Solid" BorderColor="#005f8d" BorderWidth="1" />
                                <div style="float:left;">
                                    <asp:Label ID="codeLabel" runat="server" Text='<%# Eval("code") %>' CssClass="catTitle" /> - <asp:Label CssClass="catTitle" ID="titleLabel" runat="server" Text='<%# Eval("title") %>' />
                                    <br />
                                    <asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price", "{0:c}") %>' CssClass="catPrice" />
                                    <br />
                                    <asp:Label ID="descriptionLabel" runat="server" Text='<%# Eval("description") %>' CssClass="catDesc" />
                                    <br />
                                    <asp:HyperLink ID="hlDettagli" runat="server" NavigateUrl='<%# GetItemUrl(Eval("articleID"))%>' CssClass="catDettagli">Dettagli</asp:HyperLink>
                                    <br />                  
                                    <asp:HyperLink ID="hlAddChart" runat="server" CssClass="addChart" NavigateUrl='<%# AddItemToCart(Eval("articleID"))%>' >Aggiungi al carrello</asp:HyperLink>

Imports System.Data

Partial Class catalogou
    Inherits System.Web.UI.Page
    Dim catId As Integer = 0
    Dim addToCartResponse As String = ""

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("currentLanguage") = Nothing Then
            Session("currentLanguage") = "1"
        End If

        addToCartResponse = Request.QueryString("r")
        catId = System.Convert.ToInt32(Request.QueryString("id"))

            Dim ds As DataSet
            ds = gigo_article.Query("SELECT * FROM gigo_article WHERE (categoryID = " & catId & ") ORDER BY title")

            Dim n As DataTable = New DataTable("items")

            Dim col1 As DataColumn = New DataColumn
            Dim col2 As DataColumn = New DataColumn
            Dim col3 As DataColumn = New DataColumn
            Dim col4 As DataColumn = New DataColumn
            Dim col5 As DataColumn = New DataColumn
            Dim col6 As DataColumn = New DataColumn
            Dim col7 As DataColumn = New DataColumn

            col1.ColumnName = "articleID"
            col2.ColumnName = "code"
            col3.ColumnName = "title"
            col4.ColumnName = "quantity"
            col5.ColumnName = "price"
            col6.ColumnName = "description"
            col7.ColumnName = "img"


            For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
                Dim row As DataRow

                row = n.NewRow

                row(0) = ds.Tables(0).Rows(i).Item(0).ToString
                row(1) = ds.Tables(0).Rows(i).Item(2).ToString
                row(2) = ds.Tables(0).Rows(i).Item(3).ToString
                row(3) = ds.Tables(0).Rows(i).Item(8).ToString
                row(4) = String.Format("{0:c}", (ds.Tables(0).Rows(i).Item(6)))

                Select Case Session("currentLanguage")
                    Case "1"
                        row(5) = ds.Tables(0).Rows(i).Item(4).ToString
                    Case "2"
                        row(5) = ds.Tables(0).Rows(i).Item(5).ToString
                    Case Else
                        row(5) = ds.Tables(0).Rows(i).Item(4).ToString
                End Select

                row(6) = ds.Tables(0).Rows(i).Item(7).ToString


                row = Nothing

            ProductDataList.DataSource = n

        Catch ex As Exception
        End Try


    End Sub

    Function GetItemUrl(ByVal id As Integer) As String
        Dim lnk As String = "itemDetails.aspx?id=" & id
        Return lnk
    End Function

    Function AddItemToCart(ByVal id As Integer) As String
        Dim lnk As String = "addToCart.aspx?id=" & id
        Return lnk
    End Function

End Class

Any suggestions?

Question by:xtremereality
1 Comment
LVL 26

Accepted Solution

Anurag Thakur earned 500 total points
ID: 22696112
Data List does not support pagination as supported by GridView
The following link show how to implement pagination in the datalist

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question