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

GridGroupByException: Expression cannot be null or empty

4 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael Bierch
Top achievements
Rank 1
Michael Bierch asked on 16 Sep 2011, 02:40 PM
I have a RADGrid that requires that it's columns get removed and replaced per the context under which the data is being loaded. When the grid first loads, the Grouping operation runs fine. However, when the context changes and the Grid structure is reinitialized, when I try to group by any column I get the GridGroupByException: Expression cannot be null or empty error.

I start out with a Radgrid without column definitions. When the page loads, I invoke a procedure that first clears the Grids grouping, context menu, data binding and column settings then it runs an initialization routine to configure the grid for the data that will be loaded.

Here's the code for the ClearGridSettings method that's run first:

Private Sub ClearGridSettings()
       '   -   Clear Grouping/Sort Levels
       '   -   Clear Context Menus
       '   -   Clear Data Bindings
       '   -   Clear Columns
       With grdSubmission
           'Clear Grouping/Sort Levels
           .MasterTableView.GroupByExpressions.Clear()
           .MasterTableView.SortExpressions.Clear()
           'Clear Context Menus
           .ClientSettings.ClientEvents.OnRowContextMenu = ""
           'Clear Data Bindings
           .DataSource = ""
           .DataBind()
           'Clear Columns
           .Columns.Clear()
       End With
   End Sub

Here's the code for the first Intialization:
Private Sub InitializeSubmissionGrid(ByVal GridViewSchema As Int16)
    '##########################################
    'Initialize Data Grid for Submission Claims Review
    '   -   Reset Grid
    '   -   Get GridView Schema for Submissions Claim Listing
    '   -   Implement Column Structure
    '   -   Set Miscellaneous Parameters
    '###########################################
 
    ClearGridSettings()
 
    'Get Grid View Schema for Submissions View
    Dim objDW As New DWGlobals
    Dim ds As DataSet = objDW.GetGridViewSchema(GridViewSchema)
 
    With grdSubmission
        'Add Columns to Grid
        For Each objRow As DataRow In ds.Tables(0).Rows
            Dim objCol As New GridBoundColumn()
            .MasterTableView.Columns.Add(objCol)
            objCol.DataField = objRow("ColName")
            objCol.HeaderText = objRow("ColName")
            If Not IsDBNull(objRow("FormatString")) Then
                objCol.DataFormatString = objRow("FormatString")
            End If
            objCol = Nothing
        Next
 
        ' Set Miscellaneous parameters
        .ClientSettings.Resizing.AllowResizeToFit = True
        .ClientSettings.Resizing.AllowColumnResize = True
        .ClientSettings.Scrolling.AllowScroll = True
        .ClientSettings.Scrolling.UseStaticHeaders = True
        .AutoGenerateColumns = False
        .MasterTableView.GroupsDefaultExpanded = False
        .MasterTableView.GridLines = GridLines.Both
        .MasterTableView.AllowFilteringByColumn = False
        .MasterTableView.Caption = txtSubmLabel.Text & "...(Claim Qty: " & txtClaimQty.Text & " )"
    End With
 
End Sub

Here's the initialization code for the context change that's causing the error:



Private Sub InitializeFindingsGrid(ByVal GridViewSchema As Int16)
       '##########################################
       'Initialize Data Grid for Validation Findings Review
       '   -   Reset Grid
       '   -   Get GridView Schema for Validation Findings Listing
       '   -   Implement Column Structure
       '   -   Set Miscellaneous Parameters
       '###########################################
 
       ClearGridSettings()
 
       'Get Grid View Schema for Submissions View
       Dim objDW As New DWGlobals
       Dim ds As DataSet = objDW.GetGridViewSchema(GridViewSchema)
       objDW = Nothing
 
       Dim exp As New GridGroupByExpression()
       Dim gbf As New GridGroupByField()
 
       With grdSubmission
           'Add Columns to Grid
           For Each objRow As DataRow In ds.Tables(0).Rows
               Dim objCol As New GridBoundColumn()
               objCol.DataField = objRow("ColName")
               objCol.HeaderText = objRow("ColName")
               objCol.UniqueName = objRow("ColName")
               If Not IsDBNull(objRow("FormatString")) Then
                   objCol.DataFormatString = objRow("FormatString")
               End If
               objCol.GroupByExpression = objRow("ColName")
 
               'Add GroupByField to GroupByExpression
               'gbf = New GridGroupByField
               'With gbf
               '    .FieldName = objRow("ColName")
               '    .HeaderText = objRow("ColName")
               '    .HeaderValueSeparator = " HeaderValSep "
               '    .Aggregate = GridAggregateFunction.Count
               'End With
               'exp.SelectFields.Add(gbf)
               .MasterTableView.Columns.Add(objCol)
               objCol = Nothing
           Next
 
           'Add GroupByExpression object to table
           ' .MasterTableView.GroupByExpressions.Add(exp)
 
           ' Set Miscellaneous parameters
           .ClientSettings.Resizing.AllowResizeToFit = True
           .ClientSettings.Resizing.AllowColumnResize = True
           .ClientSettings.Scrolling.AllowScroll = True
           .ClientSettings.Scrolling.UseStaticHeaders = True
           .AutoGenerateColumns = False
           .MasterTableView.GroupsDefaultExpanded = False
           .MasterTableView.GridLines = GridLines.Both
           .MasterTableView.AllowFilteringByColumn = False
           .MasterTableView.Caption = "Findings For " & txtSubmLabel.Text & _
                                      "...( " & txtFindingType.Text & ")"
           'Enable Grid Options for Findings Review
           .AllowMultiRowSelection = True
           .ClientSettings.Selecting.AllowRowSelect = True
           .ClientSettings.Selecting.EnableDragToSelectRows = True
           .ClientSettings.ClientEvents.OnRowContextMenu = "RowContextMenu"
 
       End With
 
       exp = Nothing
       gbf = Nothing
 
   End Sub

As you can see by the commented out section I tried to explicitly set GridGroupByFields but that didn't work either. I also tried setting the GroupByExpression on a column by column basis with the same result.

What am I missing?

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Sep 2011, 02:56 PM
Hello,

please look in this.
or
also give  GroupByExpression="CustomerID Group By CustomerID" in your every column.

Note : i am not sure but as per my idea the problem in objCol.GroupByExpression = objRow("ColName")
correct way : objcol.GroupByExpression = objRow("ColName Group  By ColName")

Thanks,
Jayesh Goyani
0
Michael Bierch
Top achievements
Rank 1
answered on 16 Sep 2011, 03:43 PM
Jayesh,
Thanks for your response.

I changed the groupby expression as suggested:
objCol.GroupByExpression = objRow("ColName") & " Group By " & objRow("ColName")

However the result was the same.
I reviewed the link to Group By Expression syntax and realized when I attempted to set the GroupByExpression objects explicitly I wasn't also setting the SelectFields as well as the GroupByFields. Once I did that the grouping was working however it initialized everything with every column in the grouping header which wasn't what I intended.

So I need to figure out why the grouping isn't working when I reinitialize the grid.
0
Michael Bierch
Top achievements
Rank 1
answered on 16 Sep 2011, 03:49 PM

Jayesh,

Also, I've inserted the following code when I append the columns:

objCol.Groupable = True
objCol.GroupByExpression = objCol.GetDefaultGroupByExpression

I stepped through and verified the syntax of each column GroupByExpression but I still get the empty expression error.

0
Michael Bierch
Top achievements
Rank 1
answered on 16 Sep 2011, 08:43 PM
Ok...I figured it out although I'm not sure why it works this way.

I was comparing the code I used in both Intialization procedures and I noticed in the one that grouped properly, I appended the GridBoundColumn object to the MasterTableView.Columns collection immediately after instancing the object after which I assigned the datafield and headertext properties.

In the code where the grouping was not working, I appended the GridBoundColumn to the MasterTableView.Columns collection AFTER assiging the properties to the column object. When I relocated the code .MasterTableView.Columns.Add(objCol) immediately after the instancing declaration the grouping magically worked.

I am confused but thankful it worked.

Thanks for your input!

Mike
Tags
Grid
Asked by
Michael Bierch
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Michael Bierch
Top achievements
Rank 1
Share this question
or