Vb.net 将数据列表分成3 x 3
这是我的产品代码页。问题是,每当我在网站中添加新对象时,我的数据列表将填充新项目。因此,我可以知道如何添加代码,以便我可以使数据列表成为3x3。 谢谢 代码隐藏Vb.net 将数据列表分成3 x 3,vb.net,datalist,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
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
您已经对sql查询进行了注释以获取产品详细信息。如果您已经获取了产品详细信息,那么在数据集中您将获得产品详细信息,如名称、代码等。您想要什么?Oops。我忘了取消它的注释。我已经更改了sql查询。那么,仍然可以制作3x3数据列表吗?它不像3x3数据列表。datatable与您将通过查询获取的表完全相同。您可以像datatable.Row[rowIndex][columnName]一样访问datatable。是否有相关示例?我尝试将Dim DataRow作为新的DataRow DataRow=DataSet.TablesProducts.Rows[0]ProdID,但它给了我一个错误
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