<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<head>
<title>DataGrid AllowPaging Property</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server" src="fetchData_oledb.cs" />
<script language="C#" runat="server">
void Page_Load ( Object src, EventArgs e ) {
// need to do this only on initial load
if ( !IsPostBack ) bindGrid ( );
}
void setPagerMode ( Object src, EventArgs e ) {
myGrid.PagerStyle.Mode = ( chkNumbers.Checked ) ?
PagerMode.NumericPages : PagerMode.NextPrev;
bindGrid ( );
}
void setPage ( Object src, DataGridPageChangedEventArgs e ) {
// set CurrentPageIndex to the page the user clicked.
myGrid.CurrentPageIndex = e.NewPageIndex;
// fetch and rebind the data.
bindGrid ( );
}
void bindGrid ( ) {
string query = "SELECT * FROM Products";
myGrid.DataSource = fetchData ( query, "gear" );
myGrid.DataBind ( );
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>DataGrid AllowPaging Property</h2></div>
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<asp:checkbox id="chkNumbers" runat="server"
text="Show numeric buttons"
onCheckedChanged="setPagerMode"
autopostback />
<p>
<asp:datagrid id="myGrid" runat="server"
width="92%" cellpadding=5 font-size="9pt"
headerstyle-backcolor="lightsteelblue"
headerstyle-font-bold
itemstyle-verticalalign="top"
autogeneratecolumns=false
allowpaging pagesize=4
onPageIndexChanged="setPage">
<pagerstyle position="top"
nextpagetext="Next"
prevpagetext="Prev"
horizontalalign="right" />
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:hyperlink runat="server"
navigateurl='<%# Eval ( "ProductID", "details_gear.aspx?id={0}" ) %>'>
<img width=75 border=0 runat="server"
src='<%# Eval ( "ProductID", "~/shared/images/gear/{0}.jpg" ) %>'
alt='<%# Eval ( "Model" ) %>' />
</asp:hyperlink>
</itemtemplate>
</asp:templatecolumn>
<asp:boundcolumn headertext="Brand"
datafield="Brand" />
<asp:boundcolumn headertext="Model"
datafield="Model" />
<asp:boundcolumn headertext="Description"
datafield="Description" />
<asp:boundcolumn headertext="Price"
datafield="Price"
dataformatstring="{0:c}"
itemstyle-horizontalalign="right" />
</columns>
</asp:datagrid>
</form>
</div>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>