Solved

DataList pagination

Posted on 2008-10-11
1
876 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…

830 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