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

Filter Not Valid boolean expression?

3 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chuck Harrington
Top achievements
Rank 1
Chuck Harrington asked on 09 Jan 2013, 03:50 PM
I have been trying to use a date range filter for a RadGrid with manual filter in code behind.  I understand that it is a string expression, however no matter what I try it keeps getting an error that it is not a valid boolean expression.  Here is the aspx and code behind.  What am I missing? Thanks in advance.
<telerik:RadGrid ID="TimeGrid" AllowPaging="true" DataSourceID="DetailSource" runat="server" GridLines="None" AllowSorting="false" EnableLinqExpressions="false">
               <MasterTableView>
                    <Columns>
                        <telerik:GridBoundColumn DataField="WorkDate" HeaderText="Date" UniqueName="WDate" DataFormatString="{0:MM/dd/yy}" ItemStyle-Width="75px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Shift" HeaderText="Shift" ItemStyle-Width="25px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Reg" HeaderText="Reg" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="ShftHrs" HeaderText="ShftHrs" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="OT" HeaderText="OT" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Vac40" HeaderText="Vac 40 Hrs" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Vac48" HeaderText="Vac 48 Hrs" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Vac36" HeaderText="Vac 36 Hrs" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Sick40" HeaderText="Sick 40 Hrs" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Sick48" HeaderText="Sick 48 Hrs" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Sick36" HeaderText="Sick 36 Hrs" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Exc_Absence" HeaderText="Exc Abs Hrs" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Holiday_Worked" HeaderText="Holiday Worked" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Holiday_Not_Worked" HeaderText="Holiday Not Worked" ItemStyle-Width="35px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Comments" HeaderText="Comment" ItemStyle-Width="135px"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Additional_Comment" HeaderText="Additional Comment" ItemStyle-Width="135px"></telerik:GridBoundColumn>
                        <telerik:GridCheckBoxColumn DataField="Five" HeaderText="5%"></telerik:GridCheckBoxColumn>
                        <telerik:GridCheckBoxColumn DataField="Ten" HeaderText="10%"></telerik:GridCheckBoxColumn>
                    </Columns>
               </MasterTableView>
            </telerik:RadGrid>
**Server side
Partial Class Administration_TimesheetUserControl2
    Inherits System.Web.UI.UserControl
 
    Protected Sub PayDatesDDL_SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles PayDatesDDL.SelectedIndexChanged
        Dim strFilterExpression As String
        strFilterExpression = "(([WORKDATE] >= '" + e.Value + "') AND ([WORKDATE] <= '" + Calc_PP_EndDate(e.Value) + "'))"
        TimeGrid.MasterTableView.FilterExpression = strFilterExpression
        TimeGrid.MasterTableView.Rebind()
    End Sub
    Public Shared Function Calc_PP_EndDate(ByVal strBeginDate As String) As String
        Dim dtmEndDate As Date
        Dim dtBeginDate As Date = Date.Parse(strBeginDate)
        Dim strEndDate As String
 
        If Day(dtBeginDate) = 1 Then
            dtmEndDate = DateSerial(Year(dtBeginDate), Month(dtBeginDate), 15)
        Else
            dtmEndDate = DateSerial(Year(dtBeginDate), Month(dtBeginDate) + 1, 1 - 1)
        End If
 
        strEndDate = CType(dtmEndDate, String)
        Return (strEndDate)
    End Function
End Class

3 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 09 Jan 2013, 07:02 PM
this routine works
Protected Sub cmbShipDate_SelectedIndexChanged(o As Object, e As RadComboBoxSelectedIndexChangedEventArgs) Handles cmbShipDate.SelectedIndexChanged
    Dim filterExpression, oldFilter As String
    Dim wsOrder As WSOrderSystem
 
    wsOrder = New WSOrderSystem
    oldFilter = rgEditOrder.MasterTableView.FilterExpression
    filterExpression = wsOrder.RemoveFilter(oldFilter, "ShipDate")
    oldFilter = filterExpression
    If cmbShipDate.SelectedItem.Text = "All" Then
        filterExpression = String.Empty
    Else
        filterExpression = "([ShipDate] = '" + cmbShipDate.SelectedItem.Text + "')"
    End If
    rgEditOrder.MasterTableView.FilterExpression = wsOrder.AppendFilterExpression(oldFilter, filterExpression)
    rgEditOrder.EditIndexes.Clear()
    rgEditOrder.MasterTableView.Rebind()
End Sub

the following snippet fills the combo box
Dim ShipDate As DateTime = Nothing    
 
For i = 0 To dtStores.Rows.Count - 1
    ShipDate = Convert.ToDateTime(dtStores.Rows(i)(0))    // dtstores is a DataTable
    rcbItem = New RadComboBoxItem(ShipDate.ToShortDateString())
    cmbShipDate.Items.Add(rcbItem)
Next

and you'll need this
Public Function AppendFilterExpression(oldFilter As String, filterExpression As String) As String
    Dim sb As StringBuilder
 
    sb = New StringBuilder(oldFilter)
    If filterExpression = String.Empty Then
        Return sb.ToString()
    End If
    If sb.ToString() <> String.Empty Then
        sb.Append(" AND ")
    End If
    sb.Append(filterExpression)
    Return sb.ToString()
End Function
0
Chuck Harrington
Top achievements
Rank 1
answered on 11 Jan 2013, 04:16 PM
Thanks for your code Marianne.  One quick question.  What is the WSOrderSystem reference?  A BindingSource?  Why is it important to remove the prior filterExpression?  I am working on trying to apply your code sample in my application.  What I am trying to accomplish is a filter with a date range.  Example:  "WorkDate >= '1/1/2013' And WorkDate <= '1/15/2013'"  The end date value is calculated based on the Pay Period Begin Date selected.
0
Elliott
Top achievements
Rank 2
answered on 11 Jan 2013, 05:30 PM
WSOrderSystem is a class library holding common routines (as well as IO) - the append and remove filter methods are in it

the old filter needs to be removed from the FilterExpression string because when the dropdown changes the old filter no longer applies - there are 3 dropdowns which the grid can filter by, of which shipdate is one

hope this helps
Tags
Grid
Asked by
Chuck Harrington
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Chuck Harrington
Top achievements
Rank 1
Share this question
or