使datalist成为3 x 3

时间:2012-06-23 03:12:37

标签: vb.net datalist

这是我的产品页面背后的代码。无论何时我在网站上添加新对象,我的数据列表都会填写新项目。所以我可以知道如何添加代码,以便我可以将数据列表设置为3x3。 感谢。

背后的代码

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

这是我的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 p.ProdName, p.UnitPrice, pd.Color, pd.PDPic 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

0 个答案:

没有答案