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

Rad Grid Grouping Problem--Un group is not working properly.

4 Answers 223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rama
Top achievements
Rank 1
Rama asked on 20 Sep 2012, 08:05 AM
Hello Team,

I am using telerik rad grid and I want to use Grouping events in the telerik grid . It is working but , I am facing some problem with it. Can please help me to get out of it.

Problem is ,

I am using grouping event , why it is not firing?  I am loosing data If I did a postback like ungroup . I am even using NeedDatasouce to rebind but no use and even GroupsChanging event is not Firing. This is my sample code . Can you figure out the problem ?


<telerik:RadGrid ID="RadGrid1" runat="server" Width="95%" ShowStatusBar="true"
            AutoGenerateColumns="False" PageSize="7" AllowSorting="True" showgrouppanel="true" GroupingEnabled="true" AllowMultiRowSelection="False"
             OnDetailTableDataBind="RadGrid1_DetailTableDataBind"
           OnPreRender="RadGrid1_PreRender"  onsortcommand="RadGrid1_SortCommand" OnItemDataBound="RadGrid1_ItemDataBound" GroupsChanging="RadGrid1_GroupsChanging"  NeedDataSource ="RadGrid1_NeedDataSource">
            <PagerStyle Mode="NumericPages"></PagerStyle>
            <MasterTableView Width="100%" DataKeyNames="EnquiryId" AllowMultiColumnSorting="True"  GroupLoadMode="server"  >

            <GroupByExpressions>
            <telerik:GridGroupByExpression>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="EnquiryType" />
                </GroupByFields>
                <SelectFields>
                    <telerik:GridGroupByField FieldName="EnquiryType" />
                </SelectFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
                <DetailTables>
                    <telerik:GridTableView DataKeyNames="BusinessEnquiryId" Name="Activities" Width="100%">
                       
                        <Columns>
                        <telerik:GridBoundColumn SortExpression="ActivityDisplayName" HeaderText="Activity Type" HeaderButtonType="TextButton"
                                DataField="ActivityDisplayName" UniqueName="ActivityDisplayName">
                            </telerik:GridBoundColumn>
                             <telerik:GridBoundColumn SortExpression="DateCreated" HeaderText="Date Created" HeaderButtonType="TextButton"
                                DataField="DateCreated" UniqueName="DateCreated" DataFormatString="{0:D}">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="Message" HeaderText="Message" HeaderButtonType="TextButton"
                                DataField="Message">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn SortExpression="ActivityStatusName" HeaderText="Status" HeaderButtonType="TextButton"
                                DataField="ActivityStatusName">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="FirstName" HeaderText="FirstName" HeaderButtonType="TextButton"
                        DataField="FirstName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="LastName" HeaderText="LastName" HeaderButtonType="TextButton"
                        DataField="LastName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="EnquiryTypeName" HeaderText="EnquiryTypeName" HeaderButtonType="TextButton"
                        DataField="EnquiryTypeName">
                    </telerik:GridBoundColumn>
                   <telerik:GridTemplateColumn>
                   <ItemTemplate>
                     <asp:HyperLink ID="hyCreateActivity" runat="server" Text="Create Activity"></asp:HyperLink>
                     </ItemTemplate>
                   </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
                   <ClientSettings AllowDragToGroup="true" />
        </telerik:RadGrid>


Its very important for me. Can you guys help me get out of the problem?
           


 

4 Answers, 1 is accepted

Sort by
0
Accepted
Angel Petrov
Telerik team
answered on 24 Sep 2012, 03:48 PM
Hello Rama,

I have thoroughly examined the code provided by you and think I have located the problem. It is a syntax error in the names of the events that are being called. You just have to replace the highlighted event names in the code snippet bellow with OnGroupsChanging and OnNeedDataSource.
<telerik:RadGrid ID="RadGrid1" runat="server" Width="95%" ShowStatusBar="true"
            AutoGenerateColumns="False" PageSize="7" AllowSorting="True" showgrouppanel="true" GroupingEnabled="true" AllowMultiRowSelection="False"
             OnDetailTableDataBind="RadGrid1_DetailTableDataBind"
           OnPreRender="RadGrid1_PreRender"  onsortcommand="RadGrid1_SortCommand" OnItemDataBound="RadGrid1_ItemDataBound" GroupsChanging="RadGrid1_GroupsChanging"  NeedDataSource="RadGrid1_NeedDataSource">
For your convenience I have attached a simple project replicating your scenario.

Greetings,
Angel Petrov
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.
0
Rama
Top achievements
Rank 1
answered on 26 Sep 2012, 06:06 AM
Hello Angel Petrov ,

You are really great ...That did worked for me . Many thanks ..But , How come my code base did worked properly with that blunder mistake . ? I did not check the event names because I was able to see my rad grid with results , My code did not even through me any exception. so I did not notice it. What may be  the reason ?

I am here with another problem, that I am facing with grouping again . I don't want to confuse you by explaining my project architecture . A clear description is that, we are following N-tier and I am using a view and a stored procedure to get the data from the database and I am binding that to Rad grid . As I am using a view I wrote some entities to bind required data . This is my sample code .


  RadGrid1.DataSource = DataRepository.BusinessEnquiryProvider.Business_Enquiry_Search(RealtorAgentID, status, enquiryType, Name, ContactNumber, Email, gvRealtorAgentPager.PageNumber - 1, gvRealtorAgentPager.PageSize, out rowCount);

I want to use one column to group which is not in my table as I am getting my data through a view . When I debug my Code I am able to

   GridGroupByField existing = e.Expression.SelectFields.FindByName("EnquiryTypeName") this expression returning a true value .But still I am getting the following problem.

Field EnquiryTypeName not found in the source table. Please check the expression syntax.

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: Telerik.Web.UI.GridGroupByException: Field EnquiryTypeName not found in the source table. Please check the expression syntax.

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:

[GridGroupByException: Field EnquiryTypeName not found in the source table. Please check the expression syntax.]
   Telerik.Web.UI.GridDataSetHelper.CreateGroupByTable(DataTable SourceTable, GridTableView view) +329
   Telerik.Web.UI.GridDataSetHelper.CalcGroupByTables(GridTableView gridTableView, DataTable SourceTable, String RowFilter, Int32 FirstIndex, Int32 LastIndex, Boolean applyPaging, Boolean isCustomPaging) +52
   Telerik.Web.UI.GridEnumerableFromDataView.PerformTransformation() +2679
   Telerik.Web.UI.GridEnumerableFromDataView.TransformEnumerable() +24
   Telerik.Web.UI.GridTableView.GetEnumerator(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ArrayList dataKeysArray) +172
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +642
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +858
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +94
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +182
   Telerik.Web.UI.GridTableView.PerformSelect() +206
   Telerik.Web.UI.GridTableView.DataBind() +441
   Telerik.Web.UI.GridTableView.BindAllInHierarchyLevel() +86
   Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument) +7253
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707


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




Can you please help me for this problem .?

Thanks

Rama
0
Accepted
Angel Petrov
Telerik team
answered on 26 Sep 2012, 02:14 PM
Hi Rama,

The syntax error in the names of the events that were being called NeedDataSource and GroupsChanging did not appear because RadGrid inherits WebControl. When it checked and found that there were no such methods it added them as properties. I suppose that somewhere else you have set the DataSource of the RadGrid and that is why you saw results.
 
Regarding the error you received while grouping by column that is not in your table - you should keep in mind that  grouping works only with fields you have selected. The GridGroupByField object has to identify one of those fields. If you want to group by a certain field you should add it to the DataSource.

Regards,
Angel Petrov
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.
0
Rama
Top achievements
Rank 1
answered on 26 Sep 2012, 02:29 PM
Hello Angel,

Thank you very much Angel. My problem got resolved .

Many Thanks

Rama
Tags
Grid
Asked by
Rama
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Rama
Top achievements
Rank 1
Share this question
or