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

RadGrid Ungroup - "Index was out of range."

3 Answers 387 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 17 Sep 2013, 08:46 PM
I've got a RadGrid that's filled dynamically with content... the single grid on the page is used for a variety of queries, so it never knows what columns are going to fill it beforehand.

I've enabled Grouping, and it works... I can drag a column to the header, and the data groups just fine.

However, when I click on the grouped column to try to return it back to the grid (so I can group by a different criteria), I get the following error:

Server Error in '/' Application.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
   System.Collections.CollectionBase.System.Collections.IList.get_Item(Int32 index) +10587351
   Telerik.Web.UI.GridGroupByExpressionCollection.get_Item(Int32 index) +56
   Telerik.Web.UI.GridGroupPanel.Ungroup(String index) +363
   Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument) +985
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9642338
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18045




Here is the code for the RadGrid I'm using:

 <telerik:RadGrid ID="lst" runat="server"  AllowPaging="True" PageSize="5"
    OnItemCommand="lst_ItemCommand"  CellSpacing="0" GridLines="None" ShowGroupPanel="True" AutoGenerateHierarchy="True"  >
       <ClientSettings AllowColumnsReorder="True" EnablePostBackOnRowClick ="true" AllowDragToGroup="True" >
          <Animation AllowColumnReorderAnimation="True" AllowColumnRevertAnimation="True" />
        </ClientSettings>
        <MasterTableView CommandItemDisplay="Top"  PageSize="100" GroupLoadMode="Client" AutoGenerateColumns="True" AllowSorting="True" EnableLinqGrouping="False" ShowGroupFooter="True" DataKeyNames="ID"  >
        <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="False" ShowExportToCsvButton="True"     ShowExportToPdfButton="True" ShowRefreshButton="False"></CommandItemSettings>

<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>

<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
                   
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>

<BatchEditingSettings EditType="Cell"></BatchEditingSettings>

<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
        </MasterTableView>
        <GroupingSettings ShowUnGroupButton="True"   />
        <SortingSettings SortedBackColor="Yellow" />
        <ExportSettings SuppressColumnDataFormatStrings="false">
<Pdf>
<PageHeader>
<LeftCell Text=""></LeftCell>

<MiddleCell Text=""></MiddleCell>

<RightCell Text=""></RightCell>
</PageHeader>

<PageFooter>
<LeftCell Text=""></LeftCell>

<MiddleCell Text=""></MiddleCell>

<RightCell Text=""></RightCell>
</PageFooter>
</Pdf>

            <Excel Format="Biff"></Excel>
        </ExportSettings>

<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>

<FilterMenu EnableImageSprites="False"></FilterMenu>
    </telerik:RadGrid>
 


Is there a setting I'm missing somewhere?  



Many thanks in advance.


Jay

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Sep 2013, 12:31 PM
Hi Jay,

Your code works fine at my end,please provide your C# code as well.Below is the code that i tried.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" PageSize="5"
    CellSpacing="0" GridLines="None" ShowGroupPanel="True" AutoGenerateHierarchy="True">
    <ClientSettings AllowColumnsReorder="True" EnablePostBackOnRowClick="true" AllowDragToGroup="True">
        <Animation AllowColumnReorderAnimation="True" AllowColumnRevertAnimation="True" />
    </ClientSettings>
    <MasterTableView CommandItemDisplay="Top" PageSize="100" GroupLoadMode="Client" AutoGenerateColumns="True"
        AllowSorting="True" EnableLinqGrouping="False" ShowGroupFooter="True" >
        <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="False"
            ShowExportToCsvButton="True" ShowExportToPdfButton="True" ShowRefreshButton="False">
        </CommandItemSettings>
        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
        </RowIndicatorColumn>
        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
        </ExpandCollapseColumn>
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
            </EditColumn>
        </EditFormSettings>
        <BatchEditingSettings EditType="Cell"></BatchEditingSettings>
        <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
    </MasterTableView>
    <GroupingSettings ShowUnGroupButton="True" />
    <SortingSettings SortedBackColor="Yellow" />
    <ExportSettings SuppressColumnDataFormatStrings="false">
        <Pdf>
            <PageHeader>
                <LeftCell Text=""></LeftCell>
                <MiddleCell Text=""></MiddleCell>
                <RightCell Text=""></RightCell>
            </PageHeader>
            <PageFooter>
                <LeftCell Text=""></LeftCell>
                <MiddleCell Text=""></MiddleCell>
                <RightCell Text=""></RightCell>
            </PageFooter>
        </Pdf>
        <Excel Format="Biff"></Excel>
    </ExportSettings>
    <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
    <FilterMenu EnableImageSprites="False">
    </FilterMenu>
</telerik:RadGrid>

C#:
protected void Page_Load(object sender, System.EventArgs e)
   {      
       if (!IsPostBack)
       {
           RadGrid1.DataSourceID = "SqlDataSource1";
           RadGrid1.MasterTableView.DataKeyNames = new string[] { "CustomerID" };          
           RadGrid1.MasterTableView.AutoGenerateColumns = false;          
           GridBoundColumn boundColumn;
           boundColumn = new GridBoundColumn();
           RadGrid1.MasterTableView.Columns.Add(boundColumn);
           boundColumn.DataField = "CustomerID";
           boundColumn.HeaderText = "CustomerID";
           boundColumn = new GridBoundColumn();
           RadGrid1.MasterTableView.Columns.Add(boundColumn);
           boundColumn.DataField = "ContactName";
           boundColumn.HeaderText = "Contact Name";
       }
   }

Thanks,
Princy
0
Jay
Top achievements
Rank 1
answered on 19 Sep 2013, 12:34 AM
Thanks for the reply.

My code-behind is part of a larger page framework... in a nutshell, I create a variety of Generic Objects behind the scenes to push the contents into a grid.  I've trimmed out the irrelevant code, and have left just the stuff that pertains (or references) the grid I'm using.

(Also, I've tried putting in a "NeedDataSource" method, but that didn't change anything either).

Jay

<%@ Page Language="VB" MasterPageFile="~/_master/MCoP.master" Inherits="Icarus.IcarusPage"  %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
 
 
<script runat="server">
    Dim sIndex As String = "_ID"
     
     Dim cObject As New Icarus.Ops.SQLFilledObject
         
    Sub _ini(sender As Object, e As EventArgs) Handles Me.Init
        InitGrid()
    End Sub
     
    Sub InitGrid()
        cObject.Fill_Grid(lst)
    End Sub
     
    Sub lst_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles lst.ItemCommand
        If e.CommandName = RadGrid.ExportToExcelCommandName Then
             lst.ExportSettings.IgnorePaging = True
            lst.Rebind()
        End If
         
        If e.CommandName = "RowClick" Then
            e.Item.Selected = True
           
        End If
    End Sub
     
    Protected Sub lst_ColumnCreated(sender As Object, e As GridColumnCreatedEventArgs) Handles lst.ColumnCreated
        If (TypeOf e.Column Is GridBoundColumn) AndAlso e.Column.HeaderText.StartsWith("_") Then
            e.Column.Display = False
        End If 
         
    End Sub
0
Konstantin Dikov
Telerik team
answered on 20 Sep 2013, 06:09 PM
Hello Jay,

Thank you for contacting us.

You could receive such an error on RadGrid grouping if you have the "ViewState" disabled. Please note that if you want grouping to work properly you have to enable the "ViewState". More information could be found at this help article.

Also, please have in mind that complex operations (like sorting, paging, grouping, etc.) of the RadGrid are not handled automatically if Simple data-binding is used. In case of Simple data-binding usage, a data source should be assign to the RadGrid on every operation.

Hope that helps.

Regards,
Konstantin Dikov
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Jay
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jay
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or