DataGrid Paging - Index out of Range Error

Discussion in 'ASP .Net Web Controls' started by Bill Byrd, Oct 13, 2003.

  1. Bill Byrd

    Bill Byrd Guest

    I am attempting to implement paging with a DataGrid. The
    control populates fine. The < > paging links appear.

    However when I click the > to go to the next set of
    information I receive "Server Error in ... Application.
    Index was out of range. Must be non-negative and less than
    the size of the collection. Parameter name: index.

    The code in my PageIndexChanged sub is not being reached.

    The > link does a __doPostBack("DataGrid1:ctl8:ctl1","")

    I can not find the where or why of this error.

    Please email me with you thoughts ro ideas.

    Thanks - Bill
     
    Bill Byrd, Oct 13, 2003
    #1
    1. Advertising

  2. Hi Bill,

    Please try this sample code. It may lead you in the right direction.

    * Place a datagrid on a form
    * Add this code.

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
    DataGrid1.AllowPaging = True
    DataGrid1.PageSize = 10
    DataGrid1.PagerStyle.Mode = PagerMode.NextPrev
    DataGrid1.PagerStyle.NextPageText = "Next"
    DataGrid1.PagerStyle.PrevPageText = "Prev"
    Bind()
    End If
    End Sub

    Private Sub Bind()
    Dim connectionString As String = "server='localhost';
    trusted_connection=true; Database='pubs'"
    Dim cnn As SqlConnection = New
    System.Data.SqlClient.SqlConnection(connectionString)
    Dim queryString As String = "SELECT [authors].[au_id],
    [authors].[au_lname], [authors].[au_fname] FROM [authors]"
    Dim da As SqlDataAdapter = New SqlDataAdapter(queryString, cnn)
    Dim ds As New DataSet()
    da.Fill(ds, "pubs")
    DataGrid1.DataSource = ds.Tables("pubs")
    DataGrid1.DataBind()
    da.Dispose()
    cnn.Close()
    cnn.Dispose()
    End Sub

    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
    DataGrid1.PageIndexChanged
    DataGrid1.CurrentPageIndex = e.NewPageIndex
    Bind()
    End Sub


    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    http://www.microsoft.com/protect site and perform the three straightforward
    steps listed to improve your computer’s security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > Content-Class: urn:content-classes:message
    > From: "Bill Byrd" <>
    > Sender: "Bill Byrd" <>
    > Subject: DataGrid Paging - Index out of Range Error
    > Date: Mon, 13 Oct 2003 09:13:54 -0700
    > Lines: 17
    > Message-ID: <2980601c391a4$ff7b4a80$>
    > MIME-Version: 1.0
    > Content-Type: text/plain;
    > charset="iso-8859-1"
    > Content-Transfer-Encoding: 7bit
    > X-Newsreader: Microsoft CDO for Windows 2000
    > X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    > Thread-Index: AcORpP97rCP5Xsm/TyufJfv/Uee4OA==
    > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > Path: cpmsftngxa06.phx.gbl
    > Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webcontrols:15325
    > NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    >
    > I am attempting to implement paging with a DataGrid. The
    > control populates fine. The < > paging links appear.
    >
    > However when I click the > to go to the next set of
    > information I receive "Server Error in ... Application.
    > Index was out of range. Must be non-negative and less than
    > the size of the collection. Parameter name: index.
    >
    > The code in my PageIndexChanged sub is not being reached.
    >
    > The > link does a __doPostBack("DataGrid1:ctl8:ctl1","")
    >
    > I can not find the where or why of this error.
    >
    > Please email me with you thoughts ro ideas.
    >
    > Thanks - Bill
    >
     
    Mike Moore [MSFT], Oct 14, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Clark Choi
    Replies:
    1
    Views:
    4,524
    Alvin Bruney
    Jan 10, 2004
  2. =?Utf-8?B?UnVkeQ==?=

    Newbie-Index out of range error

    =?Utf-8?B?UnVkeQ==?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    439
    =?Utf-8?B?UnVkeQ==?=
    Feb 3, 2005
  3. =?Utf-8?B?UnVkeQ==?=

    Index was out of range ERROR <NEWBIE ERROR>

    =?Utf-8?B?UnVkeQ==?=, Jul 6, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    512
    =?Utf-8?B?UnVkeQ==?=
    Jul 6, 2005
  4. Pat
    Replies:
    0
    Views:
    458
  5. Maverick

    Paging problem index out of range

    Maverick, Feb 20, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    201
    Alessandro Zifiglio
    Feb 20, 2004
Loading...

Share This Page