O exemplo abaixo é a implementação da paginação em ASP.NET, mas diferentemente do código postado na área de C#, este é está escrito em VB.
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ADO" %>
<%@ Page Language="VB" Debug="true" %>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
BindGrid
End Sub
Sub MyDataGrid_Page(sender As Object, e As DataGridPageChangedEventArgs)
startIndex = MyDataGrid.CurrentPageIndex * MyDataGrid.PageSize
BindGrid
ShowStats
End Sub
Sub BindGrid()
Dim DS As DataSet
Dim MyConnection As ADOConnection
Dim MyCommand As ADODataSetCommand
MyConnection = New ADOConnection("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("data.mdb"))
MyCommand = New ADODataSetCommand("select * from Links", MyConnection)
DS = new DataSet()
MyCommand.FillDataSet(ds, "Links")
MyDataGrid.DataSource=ds.Tables("Links").DefaultView
MyDataGrid.DataBind()
ShowStats
End Sub
Sub PagerButtonClick(sender As Object, e As EventArgs)
'used by external paging UI
Dim arg As String = sender.CommandArgument
Select arg
Case "next":
If (MyDataGrid.CurrentPageIndex < (MyDataGrid.PageCount - 1)) Then
MyDataGrid.CurrentPageIndex += 1
End If
Case "prev":
If (MyDataGrid.CurrentPageIndex > 0) Then
MyDataGrid.CurrentPageIndex -= 1
End If
Case "last":
MyDataGrid.CurrentPageIndex = (MyDataGrid.PageCount - 1)
Case Else:
'page number
MyDataGrid.CurrentPageIndex = arg.ToInt32()
End Select
BindGrid
ShowStats
End Sub
Sub ShowStats()
lblCurrentIndex.Text = "CurrentPageIndex is " & MyDataGrid.CurrentPageIndex
lblPageCount.Text = "PageCount is " & MyDataGrid.PageCount
End Sub
</script>
<form runat="server">
<ASP:DataGrid id="MyDataGrid" runat="server"
AllowPaging="True"
PageSize="5"
PageCount="1"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Right"
OnPageIndexChanged="MyDataGrid_Page"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
/>
</form>
<p>
<asp:LinkButton id="btnFirst" runat="server"
Text="Go to the first page"
CommandArgument="0"
ForeColor="navy"
Font-Name="verdana" Font-size="8pt"
OnClick="PagerButtonClick"
/>
<asp:LinkButton id="btnPrev" runat="server"
Text="Previous page"
CommandArgument="prev"
ForeColor="navy"
Font-Name="verdana" Font-size="8pt"
OnClick="PagerButtonClick"
/>
<asp:LinkButton id="btnNext" runat="server"
Text="Next page"
CommandArgument="next"
ForeColor="navy"
Font-Name="verdana" Font-size="8pt"
OnClick="PagerButtonClick"
/>
<asp:LinkButton id="btnLast" runat="server"
Text="Go to the last page"
CommandArgument="last"
ForeColor="navy"
Font-Name="verdana" Font-size="8pt"
OnClick="PagerButtonClick"
/>
<p>
<table bgcolor="#eeeeee" cellpadding="6"><tr><td nowrap><font face="Verdana" size="-2">
<asp:Label id="lblCurrentIndex" runat="server" /><br>
<asp:Label id="lblPageCount" runat="server" /><br>
0 comentários:
Postar um comentário