Make datalist into 3 x 3

Posted by unknown on Stack Overflow See other posts from Stack Overflow or by unknown
Published on 2012-06-23T03:12:37Z Indexed on 2012/06/23 3:15 UTC
Read the original article Hit count: 188

Filed under:
|

This is my code behind for products page. The prodblem is that my datalist will fill in new items whenever I add a new object in the website. So may I know how to add the codes in so that I can make the datalist into 3x3. Thanks.

Code behind

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Product As New Product
        Dim DataSet As New DataSet
        Dim pds As New PagedDataSource
        DataSet = Product.GetProduct
        Session("Dataset") = DataSet
        pds.PageSize = 4
        pds.AllowPaging = True
        pds.CurrentPageIndex = 1
        Session("Page") = pds
        If Not Page.IsPostBack Then
            UpdateDatabind()
        End If
    End Sub
    Sub UpdateDatabind()
        Dim DataSet As DataSet = Session("DataSet")
        If DataSet.Tables(0).Rows.Count > 0 Then
            pds.DataSource = DataSet.Tables(0).DefaultView
            Session("Page") = pds
            dlProducts.DataSource = DataSet.Tables(0).DefaultView
            dlProducts.DataBind()
            lblCount.Text = DataSet.Tables(0).Rows.Count
        End If
    End Sub
    Private Sub dlProducts_UpdateCommand(source As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlProducts.UpdateCommand
        dlProducts.DataBind()
    End Sub

    Public Sub PrevNext_Command(source As Object, e As CommandEventArgs)
        Dim pds As PagedDataSource = Session("Page")
        Dim CurrentPage = pds.CurrentPageIndex
        If e.CommandName = "Previous" Then
            If CurrentPage < 1 Or CurrentPage = pds.IsFirstPage Then
                CurrentPage = 1
            Else
                CurrentPage -= 1
            End If
            UpdateDatabind()
        ElseIf e.CommandName = "Next" Then
            If CurrentPage > pds.PageCount Or CurrentPage = pds.IsLastPage Then
                CurrentPage = CurrentPage
            Else
                CurrentPage += 1
            End If
            UpdateDatabind()
        End If
        Response.Redirect("Products.aspx?PageIndex=" & CurrentPage)
    End Sub

this is my code for product.vb

Public Function GetProduct() As DataSet
        Dim strConn As String
        strConn = ConfigurationManager.ConnectionStrings("HomeFurnitureConnectionString").ToString
        Dim conn As New SqlConnection(strConn)
        Dim strSql As String
        'strSql = "SELECT * FROM Product p INNER JOIN ProductDetail pd ON p.ProdID = pd.ProdID  " & _
        '         "WHERE pd.PdColor = (SELECT min(PdColor) FROM ProductDetail as pd1 WHERE pd1.ProdID = p.ProdID)"
        Dim cmd As New SqlCommand(strSql, conn)
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(cmd)
        conn.Open()
        da.Fill(ds)
        conn.Close()
        Return ds
    End Function

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about datalist