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

Data does not appear in grid when creating grouping in code behind page

2 Answers 76 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 05 Nov 2014, 02:07 PM
I have an issue when trying to set up grouping in the code behind (vb.net) in that the data does not appear. 
If I set up the grouping on the aspx page the records show up.  
I have tried adding the datasource and databind before and after this code but I never get any records to appear.
I want to be able to dynamically turn certain grouping on or off depending on the user selection.
Can you tell me why the records are not showing up when I use the code behind page to create the grouping?   

        RadGrid1.MasterTableView.GroupByExpressions.Clear()
        Dim ShowFacilities As CheckBox = ctlOptions.FindControl("cbShowFacilities")
        If ShowFacilities.Checked Then
            Dim ge1 As New Telerik.Web.UI.GridGroupByExpression
            Dim gf1 As New Telerik.Web.UI.GridGroupByField
            gf1.FieldName = "Facility"
            gf1.HeaderValueSeparator = String.Empty
            gf1.HeaderText = "Facility - "
            ge1.SelectFields.Add(gf1)
            RadGrid1.MasterTableView.GroupByExpressions.Add(ge1)

            Dim ge2 As New Telerik.Web.UI.GridGroupByExpression
            Dim gf2 As New Telerik.Web.UI.GridGroupByField
            gf2.FieldName = "Name"
            gf2.HeaderValueSeparator = String.Empty
            gf2.HeaderText = " "
            ge2.SelectFields.Add(gf2)
            RadGrid1.MasterTableView.GroupByExpressions.Add(ge2)

        Else
            Dim ge2 As New Telerik.Web.UI.GridGroupByExpression
            Dim gf2 As New Telerik.Web.UI.GridGroupByField
            gf2.FieldName = "Name"
            gf2.HeaderValueSeparator = String.Empty
            gf2.HeaderText = " "
            ge2.SelectFields.Add(gf2)
            RadGrid1.MasterTableView.GroupByExpressions.Add(ge2)

        End If

RadGrid1.DataSource = MyDataSource
RadGrid1.DataBind

2 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 10 Nov 2014, 09:29 AM
Hi,

To achieve the desired functionality you neeed to add the GridGroupByField into the GridGroupByExpression.GroupByFields collection as well as into the SelectFields collection:
RadGrid1.MasterTableView.GroupByExpressions.Clear()
        Dim ShowFacilities As CheckBox = ctlOptions.FindControl("cbShowFacilities")
        If ShowFacilities.Checked Then
            Dim ge1 As New Telerik.Web.UI.GridGroupByExpression
            Dim gf1 As New Telerik.Web.UI.GridGroupByField
            gf1.FieldName = "Facility"
            gf1.HeaderValueSeparator = String.Empty
            gf1.HeaderText = "Facility - "
            ge1.SelectFields.Add(gf1)
            ge1.GroupByFields.Add(gf1)
            RadGrid1.MasterTableView.GroupByExpressions.Add(ge1)
 
            Dim ge2 As New Telerik.Web.UI.GridGroupByExpression
            Dim gf2 As New Telerik.Web.UI.GridGroupByField
            gf2.FieldName = "Name"
            gf2.HeaderValueSeparator = String.Empty
            gf2.HeaderText = " "
            ge2.SelectFields.Add(gf2)
            ge2.GroupByFields.Add(gf2)
            RadGrid1.MasterTableView.GroupByExpressions.Add(ge2)
 
        Else
            Dim ge2 As New Telerik.Web.UI.GridGroupByExpression
            Dim gf2 As New Telerik.Web.UI.GridGroupByField
            gf2.FieldName = "Name"
            gf2.HeaderValueSeparator = String.Empty
            gf2.HeaderText = " "
            ge2.SelectFields.Add(gf2)
            ge2.GroupByFields.Add(gf2)
            RadGrid1.MasterTableView.GroupByExpressions.Add(ge2)
 
        End If

More information you can find here:
http://www.telerik.com/help/aspnet-ajax/grid-group-by-programmatic-definition.html
Also I suggest you to use Advanced Data-Binding instead of simple debating in your case, because the advanced data binding is designed for cases where advanced operations as grouping are performed over the grid.

I hope this helps.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Patrick
Top achievements
Rank 1
answered on 10 Nov 2014, 02:59 PM
Thank you!  That helped a lot!  I haven't used the NeedDataSource before so I will need to dig into how that is used.
Tags
Editor
Asked by
Patrick
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Patrick
Top achievements
Rank 1
Share this question
or