Solved

DataList pagination

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

<asp:DataList ID="ProductDataList" RepeatColumns="2"  runat="server" >
                    <ItemTemplate>
                            <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>
                                <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>
                                </div>
                            </div>
                    </ItemTemplate>
        </asp:DataList>



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"))

        Try
            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"

            n.Columns.Add(col1)
            n.Columns.Add(col2)
            n.Columns.Add(col3)
            n.Columns.Add(col4)
            n.Columns.Add(col5)
            n.Columns.Add(col6)
            n.Columns.Add(col7)

            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

                n.Rows.Add(row)

                row = Nothing
            Next

            ProductDataList.DataSource = n
            ProductDataList.DataBind()

        Catch ex As Exception
            Response.Write(ex.Message)
        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?

thanks
0
Comment
Question by:xtremereality
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 26

Accepted Solution

by:
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
http://www.dotnetjohn.com/articles.aspx?articleid=48
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

732 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