Visualizzare le righe di un datagrid su pił pagine
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<HTML>
<script language="C#" runat="server">
OleDbConnection myConnection;
protected void Page_Load(Object sender, EventArgs e)
{
myConnection = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + Server.MapPath("database/utenti.mdb"));
if (!IsPostBack)
BindGrid();
}
private void BindGrid()
{
OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from utenti", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "utenti");
DataView Source = ds.Tables["utenti"].DefaultView;
MyDataGrid.DataSource=Source;
MyDataGrid.DataBind();
}
private void MyDataGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
MyDataGrid.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
</script>
<body>
<form id="Form1" runat="server">
<ASP:DATAGRID id="MyDataGrid" runat="server" Width="700px" BorderWidth="1px" BorderStyle="None"
BorderColor="#CCCCCC" BackColor="White" CellPadding="3" EnableViewState="True" 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>
<PagerStyle Mode="NumericPages"></PagerStyle>
</ASP:DATAGRID><BR>
</form>
</body>
</HTML>
Scarica il Codice...
Stampa la pagina