0

如上所述,是否可以在代码后面制作一个。以及如何从数据库中检索它?我确实在网站上看到了详细信息,但这有点令人困惑。有没有更简单的方法来做到这一点?谢谢

好的。抱歉,这是我的代码

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            UpdateDatabind()
        End If
    End Sub
    Sub UpdateDatabind()
        Dim Product As New Product
        Dim dataset As New DataSet
        Dim count As Integer
        Dim Pds As New PagedDataSource
        dataset = Product.GetProduct()
        If dataset.Tables(0).Rows.Count > 0 Then
            'For paging 
            Pds.DataSource = dataset.Tables(0).DefaultView
            Pds.AllowPaging = True
            Pds.PageSize = 1
            Pds.CurrentPageIndex = 0
            Session("Pds") = Pds            
            'Bind the datalist
            dlProducts.DataSource = dataset
            dlProducts.DataBind()
            count = dataset.Tables(0).Rows.Count
            lblCount.Text = "Total records:" & count
            lbl1.Text = "Showing Page: " & Pds.CurrentPageIndex.ToString() & " of " & Pds.PageCount.ToString()
        Else
            lblCount.Text = "No records is found"
        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)
        ' Request.CurrentExecutionFilePath
        Dim pds As PagedDataSource = Session("pds")
        Dim CurrentPage As Integer
        If Not CurrentPage = 0 Or CurrentPage < pds.PageCount Then
            CurrentPage = pds.CurrentPageIndex
            If e.CommandName = "Next" Then
                CurrentPage += 1
                Response.Redirect("~/Products.aspx?PageIndex=" & CurrentPage)
            ElseIf e.CommandName = "Previous" Then
                CurrentPage -= 1
                Response.Redirect("~/Products.aspx?PageIndex=" & CurrentPage)
            End If
        Else
            If pds.IsFirstPage Then
                lbPrev.Visible = False
                lbPrev1.Visible = False
            End If
            If pds.IsLastPage Then
                lbNext.Visible = False
                lbNext1.Visible = False
            End If
        End If
    End Sub

我可以在 datalist 中得到结果,但我似乎没有限制行和列。示例我想检索 3x3 数据列表。

4

0 回答 0