Error on postback: Specified argument was out of the range of valid values.

2 posts, 0 answers
  1. Dave
    Dave avatar
    38 posts
    Member since:
    Jul 2007

    Posted 04 Nov 2009 Link to this post

    I am receiving an exception whenever i peform any postback on a page with a grid.
    I am adding the grid's column in code and also putting the whole grid into edit mode. The datasource is a datatable. I've been using the examples from the tutorials to get started. I also have 2 linkbuttons in the CommandItemTemplate. Whenever i click on either button, i never back it to the ItemCommand, instead i receive an exception:
    DotNetNuke.Services.Exceptions.PageLoadException: Specified argument was out of the range of valid values. Parameter name: index ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: indexat System.Web.UI.ControlCollection.get_Item(Int32 index)at Telerik.Web.UI.GridTextBoxColumnEditor.LoadControlsFromContainer() ...
    I can provide the rest of the stack trace if you need.

    here is the ascx code:

    <telerik:RadGrid ID="grdProspects" runat="server" AutoGenerateColumns="false" AllowMultiRowEdit="true">  
        <ClientSettings EnableRowHoverStyle="true">  
            <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="400" /> 
        </ClientSettings> 
        <MasterTableView EditMode="InPlace" CommandItemDisplay="TopAndBottom">  
            <CommandItemStyle Height="25px" HorizontalAlign="Right" /> 
            <CommandItemTemplate> 
                <asp:LinkButton ID="lnkAddProspect" runat="server" CommandName="ADD_PROSPECT"><asp:Image ID="imgAddProspect" runat="server" ImageUrl="~/DesktopModules/BAOffice/images/ADD.gif" ToolTip="Add New Prospect" />&nbsp;Add New Prospect</asp:LinkButton> 
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
                <asp:LinkButton ID="lnkSaveProspects" runat="server" CommandName="SAVE_PROSPECTS"><asp:Image ID="Image1" runat="server" ImageUrl="~/DesktopModules/BAOffice/images/save.gif" ToolTip="Save Changes" />&nbsp;Save Changes</asp:LinkButton> 
                &nbsp;&nbsp;  
            </CommandItemTemplate> 
        </MasterTableView> 
    </telerik:RadGrid> 


    here is the vb code:
     Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
                If Not IsPostBack Then 
     
                  For Each column As SourceColumn In MyProspectEditor.SourceColumns  
     
                    Dim boundColumn As New GridBoundColumn()  
                    boundColumn.DataField = column.Name  
                    boundColumn.HeaderText = column.Name  
                    boundColumn.ReadOnly = column.IsReadOnly  
                    grdProspects.MasterTableView.Columns.Add(boundColumn)  
     
                   Next                 
     
                End If 
            End Sub
    #Region " Prospects "  
     
            Private Sub grdProspects_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdProspects.ItemCommand  
     
                Select Case e.CommandName.ToUpper  
     
                    Case "SAVE_PROSPECTS" 
                          
     
                    Case "ADD_PROSPECT" 
                          
                End Select 
            End Sub 
     
             
     
            Private Sub grdProspects_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdProspects.NeedDataSource  
                If MyProspectEditor IsNot Nothing Then 
                    grdProspects.DataSource = MyProspectEditor.GetWorkingData()  
                End If 
            End Sub 
     
            Private Sub grdProspects_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles grdProspects.PreRender  
                If Not IsPostBack Then 
                    For Each item As GridItem In grdProspects.MasterTableView.Items  
                        If TypeOf item Is GridEditableItem Then 
                            Dim editableItem As GridEditableItem = CType(item, GridDataItem)  
                            editableItem.Edit = True 
                        End If 
                    Next 
                    grdProspects.Rebind()  
                End If 
     
            End Sub 


    Any ideas?
    thanks!
  2. Dave
    Dave avatar
    38 posts
    Member since:
    Jul 2007

    Posted 04 Nov 2009 Link to this post

    OK, i found my problem. I was not adding the columns to the mastertableview first before adding the properties. As soon as i switched the order, everything worked correctly.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top