This is a migrated thread and some comments may be shown as answers.

Problem with RadListView + RadDataPager + DataKeys + ArgumentOutOfRangeException

1 Answer 30 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Alan T
Top achievements
Rank 1
Alan T asked on 09 Nov 2012, 10:21 AM
<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
            GetTelephones()
    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
            Me.rlv_telephone.DataBind()
        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.






1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 14 Nov 2012, 06:58 AM
Hello,

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,
Andrey
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.
Tags
ListView
Asked by
Alan T
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or