Problem with RadListView + RadDataPager + DataKeys + ArgumentOutOfRangeException

2 posts, 0 answers
  1. Alan T
    Alan T avatar
    125 posts
    Member since:
    Apr 2010

    Posted 09 Nov 2012 Link to this post

    <telerik:RadListView ID="rlv_telephone" runat="server" AllowPaging="true" ItemPlaceholderID="pnl_telephone" DataKeyNames="telephone_id">
    <telerik:RadDataPager ID="rdp_account_telephone" runat="server" PagedControlID="rlv_telephone"
                                                        PageSize="2" Font-Size="10px">

        Private Sub rlv_telephone_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewItemEventArgs) Handles rlv_telephone.ItemDataBound
            If TypeOf (e.Item) Is RadListViewDataItem Then
                Dim item = TryCast(e.Item, RadListViewDataItem)
                Dim datakey As DataKey = Me.rlv_telephone.DataKeyValues(item.DataItemIndex)
                TryCast(item.FindControl("btn_edittelephone"), RadButton).Attributes.Add("onclick", "openTelephone('" & datakey("telephone_id") & "')")
            End If
        End Sub  
    Private Sub rlv_telephone_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewNeedDataSourceEventArgs) Handles rlv_telephone.NeedDataSource
        End Sub
        Protected Sub GetTelephones(Optional ByVal bind As Boolean = False)
            Me.rlv_telephone.DataSource = fe_telephone.functions.get_fe_telephone_list_by_account_id(this_account_id)
            If bind Then
            End If
        End Sub

    When the page first loads its fine. When I change page it throws an error on Me.rlv_telephone.DataKeyValues(item.DataItemIndex) stating System.ArgumentOutOfRangeException.

  2. Andrey
    Andrey avatar
    836 posts

    Posted 14 Nov 2012 Link to this post


    As this help article says you should never call DataBind method when NeedDataSource event is used. Most probably this is the reason why you get the exception. Try to remove the call to the DataBind method and check whether you get the expected behavior.

    Kind regards,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top