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

3 posts, 0 answers
  1. Patrick
    Patrick avatar
    19 posts
    Member since:
    Jun 2013

    Posted 05 Nov 2014 Link to this post

    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. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 10 Nov 2014 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Patrick
    Patrick avatar
    19 posts
    Member since:
    Jun 2013

    Posted 10 Nov 2014 in reply to Radoslav Link to this post

    Thank you!  That helped a lot!  I haven't used the NeedDataSource before so I will need to dig into how that is used.
Back to Top