
Ian Parker
Top achievements
Rank 1
Ian Parker
asked on 14 Nov 2008, 06:46 PM
I'm working with a grid that requires grouping. Grouping works fine. Ungrouping, however, throws the following exception:
Specified argument was out of the range of valid values.
Parameter name: index
Can anyone tell me what this is? It's not firing through any event we seem to be trapping.
Specified argument was out of the range of valid values.
Parameter name: index
Can anyone tell me what this is? It's not firing through any event we seem to be trapping.
4 Answers, 1 is accepted
0

Kevin Babcock
Top achievements
Rank 1
answered on 16 Nov 2008, 07:49 AM
Hi Tony,
I was able to successfully implement Grouping and Ungrouping in the RadGrid without any problems. Here is a simple example I whipped up:
Perhaps the problem you are experiencing is being caused by a configuration error or some other problem in your code. If you could provide me with more details of your implementation, or even some source code to review, perhaps I could help you track down the cause of the problem.
I hope this was helpful. Let me know if you have questions.
Regards,
Kevin Babcock
I was able to successfully implement Grouping and Ungrouping in the RadGrid without any problems. Here is a simple example I whipped up:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Telerik.Examples._Default" %> |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml" > |
<head runat="server"> |
<title>Example - Un-Grouping Data in the RadGrid</title> |
</head> |
<body> |
<form id="form1" runat="server"> |
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> |
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
<AjaxSettings> |
<telerik:AjaxSetting AjaxControlID="LinkButton1"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadGrid1" /> |
<telerik:AjaxUpdatedControl ControlID="LinkButton1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="RadGrid1"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadGrid1" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
</AjaxSettings> |
</telerik:RadAjaxManager> |
<telerik:RadGrid ID="RadGrid1" runat="server" |
AllowPaging="true" |
AllowSorting="true" |
DataSourceID="SqlDataSource1" |
PageSize="10" > |
<MasterTableView |
AutoGenerateColumns="False" |
DataKeyNames="ProductID" |
DataSourceID="SqlDataSource1"> |
<GroupByExpressions> |
<telerik:GridGroupByExpression> |
<SelectFields> |
<telerik:GridGroupByField |
FieldAlias="CategoryName" |
FieldName="CategoryName" /> |
</SelectFields> |
<GroupByFields> |
<telerik:GridGroupByField |
FieldName="CategoryName" |
SortOrder="Descending" /> |
</GroupByFields> |
</telerik:GridGroupByExpression> |
</GroupByExpressions> |
<Columns> |
<telerik:GridBoundColumn |
DataField="ProductID" |
DataType="System.Int32" |
HeaderText="ProductID" |
ReadOnly="True" |
SortExpression="ProductID" |
UniqueName="ProductID"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn |
DataField="ProductName" |
HeaderText="ProductName" |
SortExpression="ProductName" |
UniqueName="ProductName"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn |
DataField="CategoryName" |
HeaderText="CategoryName" |
SortExpression="CategoryName" |
UniqueName="CategoryName"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn |
DataField="CategoryID" |
DataType="System.Int32" |
HeaderText="CategoryID" |
SortExpression="CategoryID" |
UniqueName="CategoryID"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn |
DataField="UnitPrice" |
DataType="System.Decimal" |
HeaderText="UnitPrice" |
SortExpression="UnitPrice" |
UniqueName="UnitPrice"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn |
DataField="UnitsInStock" |
DataType="System.Int16" |
HeaderText="UnitsInStock" |
SortExpression="UnitsInStock" |
UniqueName="UnitsInStock"> |
</telerik:GridBoundColumn> |
</Columns> |
</MasterTableView> |
</telerik:RadGrid> |
<asp:LinkButton ID="LinkButton1" runat="server" |
OnClick="LinkButton1_Click" |
Text="Disable Grouping" /> |
<asp:SqlDataSource ID="SqlDataSource1" runat="server" |
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" |
SelectCommand="SELECT Products.ProductID, Products.ProductName, Categories.CategoryName, Products.CategoryID, Products.UnitPrice, Products.UnitsInStock FROM Categories INNER JOIN Products ON Categories.CategoryID = Products.CategoryID"> |
</asp:SqlDataSource> |
</form> |
</body> |
</html> |
using System; |
namespace Telerik.Examples |
{ |
public partial class _Default : System.Web.UI.Page |
{ |
protected void LinkButton1_Click(object sender, EventArgs e) |
{ |
if (RadGrid1.GroupingEnabled) |
{ |
LinkButton1.Text = "Enable Grouping"; |
RadGrid1.GroupingEnabled = false; |
} |
else |
{ |
LinkButton1.Text = "Disable Grouping"; |
RadGrid1.GroupingEnabled = true; |
} |
RadGrid1.DataBind(); |
} |
} |
} |
Perhaps the problem you are experiencing is being caused by a configuration error or some other problem in your code. If you could provide me with more details of your implementation, or even some source code to review, perhaps I could help you track down the cause of the problem.
I hope this was helpful. Let me know if you have questions.
Regards,
Kevin Babcock
0

Ian Parker
Top achievements
Rank 1
answered on 17 Nov 2008, 11:32 AM
I think I need to clarify my question: how does grouping at run time work? All the examples Telerik provides deal with a data source placed on the page and knowing which columns to group by ahead of time.
The page I'm working on allows the user to filter their data at the top of the page, click a Run button, and show the results at the bottom of the page. At the bottom, I need to let users group the results at run time. Design time examples of the data source and grouping are not much help.
It seems that there is an event I should be trapping to call Rebind(), but I can't figure it out.
Any ideas?
The page I'm working on allows the user to filter their data at the top of the page, click a Run button, and show the results at the bottom of the page. At the bottom, I need to let users group the results at run time. Design time examples of the data source and grouping are not much help.
It seems that there is an event I should be trapping to call Rebind(), but I can't figure it out.
Any ideas?
0

Kevin Babcock
Top achievements
Rank 1
answered on 20 Nov 2008, 05:43 AM
Hi Tony,
You can easily allow users to group/ungroup columns dynamically by setting the RadGrid.ShowGroupPanel property to "true" and the RadGrid.ClientSettings.AllowDragToGroup property to "true". What this does is allow users to drag a column header to an area of the grid, which will then cause a postback to the server and group the data by that column. You can group by multiple columns with this method and ungroup by simple dragging the column name off of the group area. Here is an example showing how to set those properties.
If you need more control over the way items are grouped, you can set the grouping rules dynamically using the RadGrid's OnGroupsChanging event. Check out this help article for more details.
I hope this was helpful. Please let me know if you have further questions.
Regards,
Kevin Babcock
You can easily allow users to group/ungroup columns dynamically by setting the RadGrid.ShowGroupPanel property to "true" and the RadGrid.ClientSettings.AllowDragToGroup property to "true". What this does is allow users to drag a column header to an area of the grid, which will then cause a postback to the server and group the data by that column. You can group by multiple columns with this method and ungroup by simple dragging the column name off of the group area. Here is an example showing how to set those properties.
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> |
<telerik:RadGrid ID="RadGrid1" runat="server" |
AllowPaging="true" |
AutoGenerateColumns="false" |
DataSourceID="SqlDataSource1" |
PageSize="10" |
ShowGroupPanel="true"> |
<MasterTableView> |
<Columns> |
<telerik:GridBoundColumn |
DataField="ProductID" |
HeaderText="ProductID"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn |
DataField="ProductName" |
HeaderText="ProductName"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn |
DataField="CategoryName" |
HeaderText="CategoryName"> |
</telerik:GridBoundColumn> |
</Columns> |
</MasterTableView> |
<ClientSettings AllowDragToGroup="true" /> |
</telerik:RadGrid> |
<asp:SqlDataSource ID="SqlDataSource1" runat="server" |
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" |
SelectCommand="SELECT Products.ProductID, Products.ProductName, Products.CategoryID, Categories.CategoryName, Products.UnitPrice, Products.UnitsInStock FROM Categories INNER JOIN Products ON Categories.CategoryID = Products.CategoryID"> |
</asp:SqlDataSource> |
If you need more control over the way items are grouped, you can set the grouping rules dynamically using the RadGrid's OnGroupsChanging event. Check out this help article for more details.
I hope this was helpful. Please let me know if you have further questions.
Regards,
Kevin Babcock
0

Fabrice
Top achievements
Rank 1
answered on 16 Jun 2009, 09:57 AM
Hi Tony,
I just had the same issue.
I resolved it by moving the "DataSourceID" attribute from the <masterTableview> tag to the <telerik:RadGrid> tag.
Hope this will help.
Fabrice