Solved

DataList pagination

Posted on 2008-10-11
1
872 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
1 Comment
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 500 total points
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now