Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 20th, 2007, 05:51 AM
Registered User
 
Join Date: Feb 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataList DataBinding Error: IndexOutOfRange

Hi,

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:
Code:
 Dim objPds As PagedDataSource
 
  Protected Sub Page_Load()
        If Not Page.IsPostBack Then
            ItemsGet()
        End If
    End Sub

    Public Property CurrentPage() As Integer
        Get
            Dim o As Object = Me.ViewState("_CurrentPage")
            If o Is Nothing Then
                Return 0
            Else
                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
        ItemsGet()
    End Sub

    Protected Sub lnkBtnCmdPrev_Click()
        CurrentPage = CurrentPage - 1
        ItemsGet()
    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)
        da.Fill(Items)

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

        objPds.AllowPaging = True
        objPds.PageSize = 3

        objPds.CurrentPageIndex = CurrentPage - 1

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

        lnkBtnCmdPrev.Enabled = Not objPds.IsFirstPage
        lnkBtnCmdNext.Enabled = Not objPds.IsLastPage
        DataList1.DataSource = objPds
        DataList1.DataBind()

    End Sub
The corresponding ASPX file contains

Code:
 <asp:DataList ID="DataList1"  runat="server">
                    <ItemTemplate>
                     ..........
                    </ItemTemplate>
</asp:DataList>
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.
Regards
D



Similar Threads
Thread Thread Starter Forum Replies Last Post
Datalist inside datalist amit.jagtap ASP.NET 2.0 Professional 1 September 4th, 2007 05:03 AM
Databinding Error msheather ASP.NET 1.0 and 1.1 Basics 1 January 3rd, 2007 05:14 PM
Selecting Datalist before Databinding eoghan ASP.NET 1.0 and 1.1 Professional 4 November 17th, 2004 09:24 AM
Cant fill datagrid with dataset (databinding error Tsjelle Pro VB.NET 2002/2003 1 April 5th, 2004 12:36 PM





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