Datasheet
4. Save the file and run it; you'll see something like Figure 8-6:
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 of the properties as some are purely 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, which is true, allowing 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.
261
Reading From Databases
57076_Ch 8 SAN.qxd 01/12/2003 6:43 PM Page 261