Datagrid simple paging help.

liunx

Guest
Hi guys,

I am stuck with this problem for half a day now. I am using datagrid for paging to display 5 data from a MS ACCESS file called FlightInfo (see the attached FlightInfoDatabase image) BUT the problem is my NEXT button does not work. It only displays the first 5 data BUT if I clicked on NEXT button nothing happens, it suppose to display the next 5 data. Have a look at the
website.jpg I attached to see wot the website look like.

Can please any1 tell me what is wrong with my code? How do I get the Next 5----> (as shown in the image) to work?

<%@ Page Language="vb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="system.data.oledb" %>
<script runat="server">

Sub Page_Load(sender as Object, e as EventArgs)
BindData()
End Sub

Sub BindData()
'1. Create a connection
Dim strConnection as String = "Provider=Microsoft.Jet.OLEDB.4.0;"
strConnection += "Data Source=c:\flight.mdb"
Dim objConnection as new OledbConnection(strConnection)


'2. Create the command object, passing in the SQL string
Const strSQL as String = "SELECT * FROM FlightInfo"
Dim myCommand as New OledbCommand(strSQL, objConnection)

Dim objAdapter as new OledbDataAdapter(myCommand)
Dim ds as New DataSet()
objAdapter.Fill(ds)

'Set the datagrid's datasource to the DataSet and databind
dgNameList.DataSource = ds
dgNameList.DataBind()

'strConnection.Close()
objConnection.Close()
End Sub


Sub NewPage(sender As Object, e As DataGridPageChangedEventArgs)
dgNameList.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub

</script>
<html>
<head>
<form runat="server">
<asp:DataGrid id="dgNameList" runat="server" OnPageIndexChanged="NewPage" AllowPaging="True" Font-Size="10pt" Font-Name="Verdana" HorizontalAlign="Center" Width="85%" BackColor="#eeeeee" Pagesize="5">
<HeaderStyle backcolor="Black" forecolor="White" font-bold="True" horizontalalign="Center" />
<AlternatingItemStyle backcolor="White" />
<PagerStyle nextpagetext="Next 5 -->" prevpagetext="<-- Prev 5." horizontalalign="Right" />
</asp:DataGrid>
</form>
</head>
<body>
</body>
</html>Try this
Sub Page_Load(sender as Object, e as EventArgs)
If Not IsPostBack Then
BindData()
End If
End Sub
Hope it helps;I have tried this code already BUT it still does not solve the problem.
Sub Page_Load(sender as Object, e as EventArgs)
If Not IsPostBack Then
BindData()
End If
End Subwell you code sounds logic to me, try not close the connection, coz any way its useless when you use DataAdapter, coz its closes by it self.hmmm can you please show me what you mean by copying and paste the code.i didnt say copy and paste any code :confused: , i said do not use this line
objConnection.Close() because when you use DataAdabter, the connection is closed by it self.
 
Back
Top