Datasheet
Figure 8-6
This isn't much different from the drag and drop approach we used in the first example, but it uses the
.NET data classes and a
DataGrid control, rather than the Web Matrix controls
(
AccessDataSourceControl and MxDataGrid). It means this technique will work even if Web Matrix
isn't installed on the server running the page. Let's see how it works.
How It Works
The first thing to look at is the namespace change:
<%@ import Namespace="System.Data.OleDb" %>
By default, the data pages are configured to use SQL Server and therefore use the SqlClient
namespace. Since we are using Access, we have to use the OleDb namespace.
Now let's look at the declaration of the grid itself. We won't show all the properties, as some are to do
with the visual style. Instead, we'll concentrate on those that are related to the code we'll see:
<asp:datagrid id="DataGrid1" runat="server"
AllowPaging="true" PageSize="6" OnPageIndexChanged="DataGrid_Page"
AllowSorting="true" OnSortCommand="DataGrid_Sort">
Here we have the following properties defined:
❑
AllowPaging: When set to true, allows the grid to page the results. This works in a way
similar to the
MxDataGrid where the page numbers are shown at the bottom of the grid.
❑ PageSize: Defines the number of rows to show per page.
❑ OnPageIndexChanged: Defines the event procedure to call when the page number is changed.
When a page number link is clicked, the procedure defined here is run.
258
Chapter 8
57084_08.qxp 30/01/2004 8:03 PM Page 258