p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   DataList DataBinding Error: IndexOutOfRange (http://p2p.wrox.com/showthread.php?t=54301)

AnotherAspdotnetDeveloper February 20th, 2007 05:51 AM

DataList DataBinding Error: IndexOutOfRange

I am programming in ASP.net 2.0 VS 2005.

I am using PageDataSource class to page between pages in a list of Items

I am getting a runtime exception IndexOutOfRange upon calling DataList's DataBind method afterwith PageDataSource object.

Following is the code I am trying:

 Dim objPds As PagedDataSource
  Protected Sub Page_Load()
        If Not Page.IsPostBack Then
        End If
    End Sub

    Public Property CurrentPage() As Integer
            Dim o As Object = Me.ViewState("_CurrentPage")
            If o Is Nothing Then
                Return 0
                Return Convert.ToInt32(o)

            End If
        End Get
        Set(ByVal value As Integer)
            Me.ViewState("_CurrentPage") = value
        End Set
    End Property

    Protected Sub lnkBtnCmdNext_Click()
        CurrentPage = CurrentPage + 1
    End Sub

    Protected Sub lnkBtnCmdPrev_Click()
        CurrentPage = CurrentPage - 1
    End Sub

    Protected Sub ItemsGet()
        Dim Items As DataSet = New DataSet

        objPds = New PagedDataSource

        Dim da As New SqlDataAdapter("exec sp_View_Existing_Glossary", GetConnectionString)

        objPds.DataSource = Items.Tables(0).DefaultView

        objPds.AllowPaging = True
        objPds.PageSize = 3

        objPds.CurrentPageIndex = CurrentPage - 1

        lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() & " of " & _

        lnkBtnCmdPrev.Enabled = Not objPds.IsFirstPage
        lnkBtnCmdNext.Enabled = Not objPds.IsLastPage
        DataList1.DataSource = objPds

    End Sub

The corresponding ASPX file contains


 <asp:DataList ID="DataList1"  runat="server">

Please help. I get IndexOutofRange Exception upon Databind of DataList and PageDataSourceObject (indicated above in the code as bold). What am I doing wrong?

The DataSet contains 4 rows of result data

I got the source code from an 4GuysFromRolla article. This article showed for DataRepeater and said it should not be different for DataList. Hence I used the same code to structure the Datalist

Thanks in Advance.

All times are GMT -4. The time now is 04:55 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.