Datasheet
❑ Editable Grid gives a grid allowing updates to the data.
❑
Simple Stored Procedure gives a grid that uses a stored procedure for its data source.
All of these supplied templates connect to a SQL Server database, and need modification if they are to be
used with a different database. However, they provide a quick way to get pages constructed allowing
you to make a few simple changes to get what you need, rather than coding from scratch.
Let's take a look at one of these, the report with paging and sorting.
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" %>
3. In the design window select the Code tab, find the BindGrid() subroutine, and change the
code so it looks like the following:
Sub BindGrid()
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\BegASPNet11\data\Northwind.mdb"
Dim CommandText As String
If SortField = String.Empty Then
CommandText = "select * from suppliers order by CompanyName"
Else
CommandText = "select * from suppliers order by " & SortField
End If
Dim myConnection As New OleDbConnection(ConnectionString)
Dim myCommand As New OleDbDataAdapter(CommandText, myConnection)
Dim ds As New DataSet()
myCommand.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub
Use a different path if you've installed the samples in a directory other than C:\BegASPNET11.
260
Chapter 8
57076_Ch 8 SAN.qxd 01/12/2003 6:43 PM Page 260