限制datalist中的行数和列数

时间:2012-06-22 17:33:30

标签: asp.net vb.net datalist

如上所述,是否有可能在代码中生成一个。你如何从数据库中检索它?我确实看到网站的细节,但它有点令人困惑。有没有更简单的方法呢? 感谢

确定。对不起,这是我的代码

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 datalist。

0 个答案:

没有答案