DataGrid Paging...Help

I am trying to enable paging on a simple datagrid (see attached) without any luck. Can anyone help.<BR><BR>thanks,<BR>Dan<BR>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> 'Put user code to initialize the page here<BR> If Not Page.IsPostBack Then<BR> DataGrid1.DataBind()<BR> End If<BR> End Sub<BR><BR> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<BR> OleDbDataAdapter1.SelectCommand.Parameters("weight").Value = http://aspmessageboard.com/archive/index.php/TextBox1.Text<BR> OleDbDataAdapter1.Fill(DataSet21)<BR> DataGrid1.DataBind()<BR><BR> End Sub<BR> Sub binddata()<BR> OleDbDataAdapter1.SelectCommand.Parameters("weight").Value = TextBox1.Text<BR><BR> End Sub<BR><BR>End ClassIm just guessing what your problem is here, but...<BR><BR>Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles DataGrid1.PageIndexChanged<BR> DataGrid1.CurrentPageIndex = e.NewPageIndex<BR> OleDbDataAdapter1.SelectCommand.Parameters("weight").Value = TextBox1.Text<BR>OleDbDataAdapter1.Fill(DataSet21)<BR>DataGrid1.DataBind()<BR> End Sub<BR><BR>This assumes that somewhere (probably in your aspx) you turned AllowPaging=true and set PageSize to a number. <BR><BR>The problem I ran into was that even though I set those parameters in the aspx, it didn't actually switch pages when I clicked on the page numbers. So what this sub does, is change what page the grid is on, then rebind the grid so the changes take effect.What you described is the exact problem I am having (a page displays, with additional page numbers and when I click one the page stays the same). I verified that AllowPaging="true" and that OnPageIndexChanged points to the right place.<BR><BR>Any other suggestions?<BR><BR>thanks,<BR>DanCan you post your complete code?? It is probably something small that is just eluding you.Here is the VB Code and the HTML DataGrid Code at the bottom.<BR>thanks,<BR>Dan<BR><BR>Public Class WebForm2<BR> Inherits System.Web.UI.Page<BR> Protected WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter<BR> Protected WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand<BR> Protected WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection<BR> Protected WithEvents DataSet21 As rn1.DataSet2<BR> Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox<BR> Protected WithEvents Button1 As System.Web.UI.WebControls.Button<BR> Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid<BR><BR>#Region " Web Form Designer Generated Code "<BR><BR> 'This call is required by the Web Form Designer.<BR> <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<BR> Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter()<BR> Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand()<BR> Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection()<BR> Me.DataSet21 = New rn1.DataSet2()<BR> CType(Me.DataSet21, System.ComponentModel.ISupportInitialize).BeginIni t()<BR> '<BR> 'OleDbDataAdapter1<BR> '<BR> Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1<BR> Me.OleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Physical Features", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Last Name", "Last Name"), New System.Data.Common.DataColumnMapping("First Name", "First Name"), New System.Data.Common.DataColumnMapping("Middle Name", "Middle Name"), New System.Data.Common.DataColumnMapping("Sex", "Sex"), New System.Data.Common.DataColumnMapping("Weight", "Weight")})})<BR> '<BR> 'OleDbSelectCommand1<BR> '<BR> Me.OleDbSelectCommand1.CommandText = "SELECT [Last Name], [First Name], [Middle Name], Sex, Weight FROM [Physical Featu" & _<BR> "res] WHERE (Weight = ?)"<BR> Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1<BR> Me.OleDbSelectCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Weight", System.Data.OleDb.OleDbType.Decimal, 5, System.Data.ParameterDirection.Input, False, CType(3, Byte), CType(0, Byte), "Weight", System.Data.DataRowVersion.Current, Nothing))<BR> '<BR> 'OleDbConnection1<BR> '<BR> Me.OleDbConnection1.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial " & _<BR> "Catalog=MSSdb;Data Source=speed;Use Procedure for Prepare=1;Auto Translate=True;" & _<BR> "Packet Size=4096;Workstation ID=SPEED;Use Encryption for Data=False;Tag with col" & _<BR> "umn collation when possible=False"<BR> '<BR> 'DataSet21<BR> '<BR> Me.DataSet21.DataSetName = "DataSet2"<BR> Me.DataSet21.Locale = New System.Globalization.CultureInfo("en-US")<BR> Me.DataSet21.Namespace = "http://www.tempuri.org/DataSet2.xsd"<BR> CType(Me.DataSet21, System.ComponentModel.ISupportInitialize).EndInit( )<BR><BR> End Sub<BR><BR> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init<BR> 'CODEGEN: This method call is required by the Web Form Designer<BR> 'Do not modify it using the code editor.<BR> InitializeComponent()<BR> End Sub<BR><BR>#End Region<BR><BR> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> 'Put user code to initialize the page here<BR> If Not Page.IsPostBack Then<BR> BindGrid()<BR> End If<BR> End Sub<BR><BR> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<BR> OleDbDataAdapter1.SelectCommand.Parameters("weight").Value = TextBox1.Text<BR> OleDbDataAdapter1.Fill(DataSet21)<BR> BindGrid()<BR><BR> End Sub<BR><BR> Sub DataGrid_Page(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)<BR> 'Set CurrentPageIndex to page user clicked.<BR> 'DataGrid1.CurrentPageIndex = e.NewPageIndex<BR><BR> 'Rebind the data<BR> BindGrid()<BR> End Sub<BR><BR> Sub BindGrid()<BR> DataGrid1.DataSource = DataSet21<BR> DataGrid1.DataBind()<BR> End Sub<BR>End Class<BR><BR>======================================<BR><%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="rn1.WebForm2"%><BR><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><BR><HTML><BR> <HEAD><BR> <title>WebForm2</title><BR> <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0"><BR> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0"><BR> <meta name="vs_defaultClientScript" content="JavaScript"><BR> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"><BR> </HEAD><BR> <body MS_POSITIONING="GridLayout"><BR> <form id="Form1" method="post" runat="server"><BR> <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 119px; POSITION: absolute; TOP: 56px" runat="server"></asp:TextBox><BR> <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 295px; POSITION: absolute; TOP: 53px" runat="server" Text="Search"></asp:Button><BR> <asp:DataGrid id=DataGrid1 style="Z-INDEX: 103; LEFT: 80px; POSITION: absolute; TOP: 106px" runat="server" DataSource="<%# DataSet21 %>" DataMember="Physical Features" AllowPaging="True" OnPageIndexChanged="DataGrid_Page" PageSize="10"><BR> <PagerStyle Mode="NumericPages"></PagerStyle><BR> </asp:DataGrid><BR> </form><BR> </body><BR></HTML><BR>
 
Back
Top