S
Swandi Candra
Folks,
I found the following example from dotnetjunkies, which worked
fine.
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<html>
<head>
<title>ASPNextGen.com - Paging in the DataGrid Part 1</title>
<script runat="server" language="VB">
Sub Page_Load(Source As Object, E As EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
Dim ds As New DataSet
Dim dsc As SQLDataAdapter
Dim strSQL As String
Dim strCon As String
strSQL = "SELECT CompanyName, ContactName, " & _
" ContactTitle, Phone, Fax FROM Customers " & _
" ORDER BY CompanyName"
strCon = "server=localhost;database=Northwind;uid=sa;pwd=;"
dsc = New SQLDataSetCommand(strSQL, strCon)
dsc.Fill(Ds, "Customers")
myDataGrid.DataSource = ds.Tables("Customers").DefaultView
myDataGrid.DataBind()
End Sub
Sub myDataGrid_PageChanger(Source As Object, _
E As DataGridPageChangedEventArgs)
myDataGrid.CurrentPageIndex = E.NewPageIndex
BindData()
End Sub
</script>
<style>
.DataGrid {font:x-small Verdana, Arial, sans-serif}
</style>
</head>
<body>
<form runat="server" method="post">
<aspataGrid runat="server" id="myDataGrid"
Border="0"
Cellpadding="4"
Cellspacing="0"
AlternatingItemStyle-BackColor="#EFEFEF"
ShowHeader="True"
CssClass="DataGrid"
HeaderStyle-BackColor="Black"
HeaderStyle-ForeColor="White"
HeaderStyle-Font-Bold="True"
AllowPaging="True"
PageSize="10"
PagerStyle-Mode="NumericPages"
OnPageIndexChanged="myDataGrid_PageChanger"
/>
</form>
</body>
</html>
However, it used SqlClient as its provider, instead of OleDb.
Therefore, I changed the binding part as follow
Sub BindData()
Dim conn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim strSQL As String
Dim strCon As String
strSQL = "SELECT CompanyName, ContactName, " & _
" ContactTitle, Phone, Fax FROM Customers " & _
" ORDER BY CompanyName"
strCon = "server=localhost;database=Northwind;uid=sa;pwd=;"
conn = New OleDbConnection(strCon)
conn.open
cmd = new OleDbCommand()
cmd.Connection = conn
cmd.CommandText = strSQL
myDataGrid.DataSource = cmd.ExecuteReader()
myDataGrid.DataBind()
End Sub
When I ran it, the ASP.NET displayed an error indicating that
I should include AllowCustomPaging=True property in aspataGrid.
After I added it, the list can be displayed property, except with
no paging.
Does anyone know what's going on?
Can anyone suggest me, how to do it properly with OleDb provider?
Thanks for your help.
SC
I found the following example from dotnetjunkies, which worked
fine.
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<html>
<head>
<title>ASPNextGen.com - Paging in the DataGrid Part 1</title>
<script runat="server" language="VB">
Sub Page_Load(Source As Object, E As EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub BindData()
Dim ds As New DataSet
Dim dsc As SQLDataAdapter
Dim strSQL As String
Dim strCon As String
strSQL = "SELECT CompanyName, ContactName, " & _
" ContactTitle, Phone, Fax FROM Customers " & _
" ORDER BY CompanyName"
strCon = "server=localhost;database=Northwind;uid=sa;pwd=;"
dsc = New SQLDataSetCommand(strSQL, strCon)
dsc.Fill(Ds, "Customers")
myDataGrid.DataSource = ds.Tables("Customers").DefaultView
myDataGrid.DataBind()
End Sub
Sub myDataGrid_PageChanger(Source As Object, _
E As DataGridPageChangedEventArgs)
myDataGrid.CurrentPageIndex = E.NewPageIndex
BindData()
End Sub
</script>
<style>
.DataGrid {font:x-small Verdana, Arial, sans-serif}
</style>
</head>
<body>
<form runat="server" method="post">
<aspataGrid runat="server" id="myDataGrid"
Border="0"
Cellpadding="4"
Cellspacing="0"
AlternatingItemStyle-BackColor="#EFEFEF"
ShowHeader="True"
CssClass="DataGrid"
HeaderStyle-BackColor="Black"
HeaderStyle-ForeColor="White"
HeaderStyle-Font-Bold="True"
AllowPaging="True"
PageSize="10"
PagerStyle-Mode="NumericPages"
OnPageIndexChanged="myDataGrid_PageChanger"
/>
</form>
</body>
</html>
However, it used SqlClient as its provider, instead of OleDb.
Therefore, I changed the binding part as follow
Sub BindData()
Dim conn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim strSQL As String
Dim strCon As String
strSQL = "SELECT CompanyName, ContactName, " & _
" ContactTitle, Phone, Fax FROM Customers " & _
" ORDER BY CompanyName"
strCon = "server=localhost;database=Northwind;uid=sa;pwd=;"
conn = New OleDbConnection(strCon)
conn.open
cmd = new OleDbCommand()
cmd.Connection = conn
cmd.CommandText = strSQL
myDataGrid.DataSource = cmd.ExecuteReader()
myDataGrid.DataBind()
End Sub
When I ran it, the ASP.NET displayed an error indicating that
I should include AllowCustomPaging=True property in aspataGrid.
After I added it, the list can be displayed property, except with
no paging.
Does anyone know what's going on?
Can anyone suggest me, how to do it properly with OleDb provider?
Thanks for your help.
SC