Visualizzare le righe di un datagrid su più pagine (utilizzando delle immagini per lo scorrimento)
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<HTML>
<script language="VB" runat="server">
Dim MyConnection As OleDbConnection
Public Sub Page_Load(ByVal Sender As System.Object, ByVal E As System.EventArgs) Handles MyBase.Load
MyConnection = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" & Server.MapPath("database/utenti.mdb"))
MyDataGrid.PagerStyle.PrevPageText = "<IMG title='Precedente' height='14' width='15' hspace='2' src='immagini/prev.gif' border='0'>"
MyDataGrid.PagerStyle.NextPageText = "<IMG title='Successiva' height='14' width='15' hspace='2' src='immagini/next.gif' border='0'>"
If Not (IsPostBack) Then
BindGrid()
End If
End Sub
Sub BindGrid()
Dim DS As DataSet
Dim MyCommand As OleDbDataAdapter
MyCommand = New OleDbDataAdapter("select * from utenti", MyConnection)
DS = New DataSet
MyCommand.Fill(DS, "utenti")
Dim Source As DataView = DS.Tables("utenti").DefaultView
MyDataGrid.DataSource = Source
MyDataGrid.DataBind()
End Sub
Sub MyDataGrid_PageIndexChanged(source As object, e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
</script>
<body>
<form runat="server" ID="Form1">
<ASP:DATAGRID id="MyDataGrid" runat="server" Width="700px" BorderWidth="1px" BorderStyle="None"
BorderColor="#CCCCCC" BackColor="White" CellPadding="3" Font-Names="Verdana" HeaderStyle-BackColor="#aaaadd"
Font-Size="8pt" Font-Name="Verdana" PageSize="3" AllowPaging="True" OnPageIndexChanged="MyDataGrid_PageIndexChanged">
<ItemStyle ForeColor="#000066"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#006699"></HeaderStyle>
</ASP:DATAGRID><BR>
</form>
</body>
</HTML>