HOME > .NET Framework > Forum > AllowPaging Error คือเขียน select ข้อมูลแล้วเอา GridView มารับแบบนี้นะ The data source does not support server-side data paging
AllowPaging Error คือเขียน select ข้อมูลแล้วเอา GridView มารับแบบนี้นะ The data source does not support server-side data paging
Dim myConn As SqlConnection
myConn = New SqlConnection(ConfigurationManager.ConnectionStrings("Toyota_3ConnectionString").ConnectionString)
Dim myCommand As SqlCommand = New SqlCommand()
myCommand.CommandText = "SELECT [ID_Cus] As ID , [Name] As ชื่อ , [LastName]As สกุล, [NO_Contract] As เลขที่สัญญา, [Model] As รุ่น, [Color] As สี, [NO_Coach] As เลขโครงรถ , [NO_Machine] As เลขเครื่องยนต์ , [Car_Code] As เลขทะเบียน , [City_Code] As จังหวัด , [Due_Date] As ครบวันดิว , [Amount_2] As ยอค้าง"
myCommand.CommandText &= " FROM [Customer]"
myCommand.CommandText &= " WHERE [Name] LIKE '%" & TextBox1.Text & "%'"
'MsgBox(myCommand.CommandText)
myCommand.CommandType = CommandType.Text
myCommand.Connection = myConn
myCommand.Connection.Open()
Dim myReader As SqlDataReader
myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
GridView1.DataSource = myReader
GridView1.DataBind()
myCommand.Dispose()
myConn.Dispose()
แล้วต้องการ set AllowPaging = True แต่มัน Error ค่ะ
Error ว่า The data source does not support server-side data paging.
ตรงบรรทัด GridView1.DataBind ต้องแก้อย่างไรค่ะ
ปล.ตอนยังไม่ได้ Set AllowPaging = True มัน Run ได้นะค่ะ ไม่ Error
<%@ 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 GridView ***'
myGridView.DataSource = ds
myGridView.DataBind()
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
End Sub
Sub ShowPageCommand(s As Object, e As GridViewPageEventArgs)
myGridView.PageIndex = e.NewPageIndex
BindData()
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - GridView</title>
</head>
<body>
<form id="form1" runat="server" >
<asp:GridView id="myGridView" PageSize="2" OnPageIndexChanging="ShowPageCommand" AllowPaging="True" runat="server">
<HeaderStyle BackColor="#cccccc"></HeaderStyle>
<AlternatingRowStyle BackColor="Gainsboro"></AlternatingRowStyle>
</asp:GridView>
</form>
</body>
</html>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
BindData()
End Sub
Sub BindData()
'*** DataSet ***'
Dim ds As DataSet
ds = CreateDataSet()
myRepeater.DataSource = ds.Tables(0).DefaultView
myRepeater.DataBind()
End Sub
'*** DataSet ***'
Function CreateDataSet() As DataSet
Dim objConn As New System.Data.SqlClient.SqlConnection
Dim objCmd As New System.Data.SqlClient.SqlCommand
Dim dtAdapter As New System.Data.SqlClient.SqlDataAdapter
Dim ds As New DataSet
Dim strConnString,strSQL As String
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
strSQL = "SELECT * FROM customer"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Return ds '*** Return DataSet ***'
End Function
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - System.Data.SqlClient</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater id="myRepeater" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th>CustomerID</th>
<th>Name</th>
<th>Email</th>
<th>CountryCode</th>
<th>Budget</th>
<th>Used</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center"><%#Container.DataItem("CustomerID") %></td>
<td><%#Container.DataItem("Name") %></td>
<td><%#Container.DataItem("Email") %></td>
<td align="center"><%#Container.DataItem("CountryCode") %></td>
<td align="right"><%#Container.DataItem("Budget") %></td>
<td align="right"><%#Container.DataItem("Used") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>
<%@ 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 GridView ***'
myGridView.DataSource = ds
myGridView.DataBind()
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
End Sub
Sub ShowPageCommand(s As Object, e As GridViewPageEventArgs)
myGridView.PageIndex = e.NewPageIndex
BindData()
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - GridView</title>
</head>
<body>
<form id="form1" runat="server" >
<asp:GridView id="myGridView" PageSize="2" OnPageIndexChanging="ShowPageCommand" AllowPaging="True" runat="server">
<HeaderStyle BackColor="#cccccc"></HeaderStyle>
<AlternatingRowStyle BackColor="Gainsboro"></AlternatingRowStyle>
</asp:GridView>
</form>
</body>
</html>