01.
<%@ Import
Namespace
=
"System.Data"
%>
02.
<%@ Import
Namespace
=
"System.Data.OleDb"
%>
03.
<%@ Page Language=
"VB"
%>
04.
<script runat=
"server"
>
05.
Sub
Page_Load(sender
As
Object
, e
As
EventArgs)
06.
IF
Not
Page.IsPostBack()
Then
07.
BindData()
08.
End
IF
09.
End
Sub
10.
11.
Sub
BindData()
12.
13.
Dim
objConn
As
New
OleDbConnection
14.
Dim
objCmd
As
New
OleDbCommand
15.
Dim
dtAdapter
As
New
OleDbDataAdapter
16.
Dim
ds
As
New
DataSet
17.
Dim
strConnString,strSQL
As
String
18.
19.
strConnString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& _
20.
Server.MapPath(
"database/mydatabase.mdb"
)&
";"
21.
strSQL =
"SELECT * FROM customer"
22.
23.
objConn.ConnectionString = strConnString
24.
With
objCmd
25.
.Connection = objConn
26.
.CommandText = strSQL
27.
.CommandType = CommandType.Text
28.
End
With
29.
dtAdapter.SelectCommand = objCmd
30.
31.
dtAdapter.Fill(ds)
32.
33.
34.
myGridView.DataSource = ds
35.
myGridView.DataBind()
36.
37.
dtAdapter =
Nothing
38.
objConn.Close()
39.
objConn =
Nothing
40.
41.
End
Sub
42.
43.
Sub
ShowPageCommand(s
As
Object
, e
As
GridViewPageEventArgs)
44.
myGridView.PageIndex = e.NewPageIndex
45.
BindData()
46.
End
Sub
47.
</script>
48.
<html>
49.
<head>
50.
<title>ThaiCreate.Com ASP.NET - GridView</title>
51.
</head>
52.
<body>
53.
<form id=
"form1"
runat=
"server"
>
54.
<asp:GridView id=
"myGridView"
PageSize=
"2"
OnPageIndexChanging=
"ShowPageCommand"
AllowPaging=
"True"
runat=
"server"
>
55.
<HeaderStyle BackColor=
"#cccccc"
></HeaderStyle>
56.
<AlternatingRowStyle BackColor=
"Gainsboro"
></AlternatingRowStyle>
57.
</asp:GridView>
58.
</form>
59.
</body>
60.
</html>