Weehobbemimus
New Member
I am trying to implement custom paging and I am having problems. I can get the results to split into pages like expected, but when I click on a page number it simply shows the same first two records. Furthermore, when I click on say page 3 the first time, the page reloads but "3" still appears as a link. It's only when I click "3" again or some other number that "3" appears as a non-link.<BR><BR>Here is my code:<BR><BR><BR><% @Page Language="VB" Debug="true" %><BR><% @Import Namespace="System.Data" %><BR><% @Import Namespace="System.Data.OleDb" %><BR><!-- #include virtual="AutoPerformanceSearchCommon.aspx" --><BR><!-- #include virtual="IsBlank.aspx" --><BR><script language="VB" runat="server"><BR><BR>Dim gstrMakeName As String<BR>Dim gstrModelName As String<BR>Dim gintModelYear As Integer<BR><BR>Sub Page_Load(sender as Object, e as EventArgs)<BR><BR> If Not Page.IsPostBack Then<BR> <BR> gstrMakeName = Request("lstMakeName")<BR> gstrModelName = Request("txtModelName")<BR> <BR> If IsBlank( Request("txtModelYear") ) = False And IsNumeric( Request("txtModelYear") ) = True Then<BR> gintModelYear = CInt(Request("txtModelYear"))<BR> Else<BR> gintModelYear = 0<BR> End If<BR> <BR> ConnectToAutosDatabase( AutoPerformanceGlobals.gstrConnectionString ) <BR> SetSearchListInfo( gstrMakeName, gstrModelName, gintModelYear )<BR> DisconnectFromAutosDatabase()<BR> <BR> End If<BR> <BR>End Sub<BR><BR>Sub GridChangePage(sender As Object, e As DataGridPageChangedEventArgs)<BR><BR> dgPerformanceSearchList.CurrentPageIndex = e.NewPageIndex<BR> ConnectToAutosDatabase( AutoPerformanceGlobals.gstrConnectionString ) <BR> SetSearchListInfo( gstrMakeName, gstrModelName, gintModelYear )<BR> DisconnectFromAutosDatabase()<BR><BR>End Sub<BR><BR><BR><BR>Sub SetSearchListInfo( strMakeName As String, strModelName As String, intModelYear As Integer)<BR><BR> Dim objDataAdapter As OleDbDataAdapter<BR> Dim objDataSet As DataSet<BR> Dim objCommand As OleDbCommand<BR> Dim objMakeNameParameter As OleDbParameter<BR> Dim objModelNameParameter As OleDbParameter<BR> Dim objModelYearParameter As OleDbParameter<BR> <BR> 'create a command and set it's properties<BR> objCommand = New OLEDBCommand() <BR> With objCommand <BR> .Connection = gcnnAutos<BR> .CommandType = CommandType.StoredProcedure <BR> .CommandText = "sp_ModelInformationAndPerformanceResults" <BR> <BR> objModelNameParameter = .Parameters.Add( "@strModelName", OleDbType.VarChar, 50 )<BR> objMakeNameParameter = .Parameters.Add( "@strMakeName", OleDbType.VarChar, 50 )<BR> objModelYearParameter = .Parameters.Add( "@intModelYear", OleDbType.Integer )<BR> <BR> 'if any of the parameters are blank, do not set a value for them <BR> If IsBlank( strModelName ) = False Then <BR> objModelNameParameter.Value = http://aspmessageboard.com/archive/index.php/strModelName<BR> End If <BR> If IsBlank( strMakeName ) = False Then<BR> objMakeNameParameter.Value = strMakeName<BR> End If <BR> If intModelYear > 0 Then<BR> objModelYearParameter.Value = intModelYear<BR> End If<BR> <BR> End With<BR> <BR> 'create a data adapter and load a dataset with the results of the command<BR> objDataAdapter = New OleDbDataAdapter() <BR> With objDataAdapter<BR> <BR> .SelectCommand = objCommand<BR> objDataSet = New DataSet() <BR> .Fill(objDataSet, "Results")<BR> <BR> 'if the database was called and info was returned, bind the data and return true<BR> 'else, return false<BR> If Not objDataSet.Tables("Results") Is Nothing Then<BR> With dgPerformanceSearchList<BR> .PagerStyle.Mode = PagerMode.NumericPages <BR> .VirtualItemCount = objDataSet.Tables("Results").Rows.Count <BR> .DataSource = objDataSet.Tables("Results").DefaultView<BR> .DataBind()<BR> End With<BR> End If <BR> <BR> End With<BR> <BR>End Sub<BR> <BR></script><BR><BODY><BR><form runat="server" name="PerformanceSearchList"><BR><asp:datagrid <BR> id="dgPerformanceSearchList" <BR> runat="server" <BR> AutoGenerateColumns="False"<BR> AllowPaging="true"<BR> AllowCustomPaging="true"<BR> OnPageIndexChanged="GridChangePage"<BR> PageSize="2"><BR> <PagerStyle NextPageText="Forward"<BR> PrevPageText="Back" <BR> Position="Bottom"><BR> </PagerStyle> <BR> <Columns><BR> <asp:BoundColumn DataField="ModelName" HeaderText="Model Name"/><BR> <asp:BoundColumn DataField="MakeName" HeaderText="Make Name"/><BR> </Columns><BR> <BR></asp:datagrid><BR></form><BR></BODY><BR></HTML>