Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DataList pagination

Posted on 2008-10-11
1
Medium Priority
?
881 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 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