<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
IF Not Page.IsPostBack() Then
BindData()
End IF
End Sub
Sub BindData()
Dim objConn As New OleDbConnection
Dim objCmd As New OleDbCommand
Dim dtAdapter As New OleDbDataAdapter
Dim ds As New DataSet
Dim strConnString,strSQL As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("database/mydatabase.mdb")&";"
strSQL = "SELECT * FROM customer"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
'*** BindData to DataGrid ***'
myDataGrid.DataSource = ds
myDataGrid.DataBind()
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
End Sub
Sub ShowPageCommand(sender As Object, e As DataGridPageChangedEventArgs)
myDataGrid.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - DataGrid</title>
</head>
<body>
<form id="form1" runat="server" >
<asp:DataGrid id="myDataGrid" PageSize="2" OnPageIndexChanged="ShowPageCommand"
AllowPaging="True" runat="server">
<HeaderStyle BackColor="#cccccc"></HeaderStyle>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
</asp:DataGrid>
</form>
</body>
</html>