Datasheet
Try It Out Creating a Data Page
1.
Create a new page using the Data Pages templates. Pick the Data Report with Paging and Sorting,
and call it
SortPage.aspx.
2. In the design window, select the All tab and change this line:
<%@ import Namespace="System.Data.SqlClient" %>
To:
<%@ import Namespace ="System.Data.OleDb" %>
If this is not done, errors will be encountered while loading the page.
3. In the design window, select the Code tab, find the BindGrid() subroutine, and change the
code so it looks like the following:
void BindGrid()
{
// TODO: update the ConnectionString value for your application
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=C:\BegASPNet11\data\Northwind.mdb";
string CommandText;
// TODO: update the CommandText value for your application
if (SortField == String.Empty)
CommandText = "select * from Suppliers order by CompanyName";
else
CommandText = "select * from Suppliers order by " + SortField;
OleDbConnection myConnection = new OleDbConnection(ConnectionString);
OleDbDataAdapter myCommand = new OleDbDataAdapter(CommandText,
myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
Use a different path if you've installed the samples in a directory other than C:\BegASPNET11.
4. Save the file and run it; you'll see something like Figure 8-6:
257
Reading from Databases
57084_08.qxp 30/01/2004 8:03 PM Page 257