Salve a tutti,
ho creato questa pagina con webmatrix...in teoria dovrebbe recuperami i dati da Comuni.mdb e impaginarli su più pagine 1,2,3 ecc.
Non capisco perchè non mi da errore ma non mi recupera neanche i record. Quando la testo veedo solo il titolo della pagina.
Vi riporto il codice di seguito.
Vi sarei grato se qualcuno provasse ad azzizzarla...cioè a farla funzicare bene.
Il database lo potete scaricare da qui (tra l'altro potrebbe esservi molto utile):
http://www.vlcsoftware.it/downloads/Varie/vlccomuni.asp
<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
BindGrid();
}
}
void DataGrid_Page(object sender, DataGridPageChangedEventArgs e) {
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
void BindGrid() {
string ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + Server.MapPath("/mdb-database/comuni.mdb");
string CommandText = "select ID, CAPOLUOGO, PROVINCIA, COMUNI, CODICE_PROVINCIA from PROVINCE order by CAPOLUOGO";
OleDbConnection myConnection = new OleDbConnection(ConnectionString);
OleDbCommand myCommand = new OleDbCommand(CommandText, myConnection);
myConnection.Open();
DataGrid1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConne ction);
DataGrid1.DataBind();
}
</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<h2>Prova paginazione
</h2>
<hr size="1" />
<form runat="server">
<asp:datagrid id="DataGrid1" runat="server" AllowPaging="true" PageSize="6" OnPageIndexChanged="DataGrid_Page" ForeColor="Black" BackColor="White" CellPadding="3" GridLines="None" CellSpacing="1" width="80%">
<HeaderStyle font-bold="True" forecolor="white" backcolor="#4A3C8C"></HeaderStyle>
<PagerStyle horizontalalign="Right" backcolor="#C6C3C6" mode="NumericPages"></PagerStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
</asp:datagrid>
</form>
</body>
</html>
Grazie
Diego:master: