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

Grid does not show results when binding

1 Answer 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ahmed Ilyas
Top achievements
Rank 1
Ahmed Ilyas asked on 04 Apr 2012, 05:18 PM
Using RadControls I believe.
We have a DateTimePicker and need to do custom filtering on Date only.
I have implemented the code on the ItemCommand event and then I filter a dataset and then finally set the datasource to the grid and bind. I know there are results in there but the grid shows "no results"

any ideas?
<telerik:GridDateTimeColumn FilterControlWidth="60px" AllowFiltering="true" AutoPostBackOnFilter="false"
                        CurrentFilterFunction="Contains" HeaderStyle-HorizontalAlign="Center" DataField="DateTime"
                        HeaderText="Date" SortExpression="DateTime" ShowFilterIcon="true" UniqueName="DateTime"
                        PickerType="DatePicker" DataFormatString="{0:g}" DataType="System.DateTime">
                         
                        <HeaderStyle Width="100px" HorizontalAlign="center"></HeaderStyle>
                        <ItemStyle HorizontalAlign="center" Width="100px"></ItemStyle>
                         
                    </telerik:GridDateTimeColumn>


Code:

Protected Sub grdShiftObservation_OnItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdShiftObservation.ItemCommand
 
        If e.CommandName = RadGrid.FilterCommandName Then
 
            Dim filterPair As Pair = DirectCast(e.CommandArgument, Pair)
 
            Select Case filterPair.Second.ToString()
                Case "DateTime"
                    Dim filterOption As String = CType(e.CommandArgument, Pair).First
 
                    Dim filterItem As GridFilteringItem = CType(e.Item, GridFilteringItem)
                    Dim currentPattern As String = CType(filterItem(CType(e.CommandArgument, Pair).Second).Controls(0), RadDatePicker).SelectedDate
 
                    If Not String.IsNullOrEmpty(currentPattern) Then
                        Dim dt As DateTime = Convert.ToDateTime(currentPattern)
 
                        Dim dtFromString As String = dt.ToString("MM/dd/yyyy") & " 00:00:00" ' i.e the date they selected in the picker
                        Dim dtToString As String = dt.AddDays(1).ToString("MM/dd/yyyy") & " 00:00:00"
 
                        Dim filterPatternAssist As String = String.Empty
                        Dim dateColumn As GridBoundColumn = CType(e.Item.OwnerTableView.GetColumnSafe("DateTime"), GridBoundColumn)
 
                        Select Case filterOption
                            Case "EqualTo"
                                dtFromString = "DateTime >= #" & dtFromString & "# AND DateTime < #" & dtToString & "#"
                                dateColumn.CurrentFilterFunction = GridKnownFunction.EqualTo
                            Case "NotEqualTo"
                                dtFromString = "Not DateTime = #" & dtFromString & "#"
                                dateColumn.CurrentFilterFunction = GridKnownFunction.NotEqualTo
                            Case "GreaterThan"
                                dtFromString = "DateTime > #" & dtFromString & "#"
                                dateColumn.CurrentFilterFunction = GridKnownFunction.GreaterThan
                            Case "LessThan"
                                dtFromString = "DateTime < #" & dtFromString & "#"
                                dateColumn.CurrentFilterFunction = GridKnownFunction.LessThan
                            Case "GreaterThanOrEqualTo"
                                dtFromString = "DateTime >= #" & dtFromString & "#"
                                dateColumn.CurrentFilterFunction = GridKnownFunction.GreaterThanOrEqualTo
                            Case "LessThanOrEqualTo"
                                dtFromString = "DateTime <= #" & dtFromString & "#"
                                dateColumn.CurrentFilterFunction = GridKnownFunction.LessThanOrEqualTo
                            Case "Between"
                                dtFromString = "#" & dtFromString & "' <= DateTime AND DateTime <= #" & filterPatternAssist & "#"
                                dateColumn.CurrentFilterFunction = GridKnownFunction.Between
                            Case "NoFilter"
                                dtFromString = String.Empty
                                dateColumn.CurrentFilterFunction = GridKnownFunction.NoFilter
                            Case "NotBetween"
                                dtFromString = "DateTime <= #" & dtFromString & "' OR DateTime >= #" & filterPatternAssist & "#"
                                dateColumn.CurrentFilterFunction = GridKnownFunction.NotBetween
                            Case "IsNull"
                            Case "NotIsNull"
                            Case "Contains"
                                dtFromString = String.Empty
                                dateColumn.CurrentFilterFunction = GridKnownFunction.NoFilter
                        End Select
 
                        FilterGrid(dtFromString)
 
                    End If
            End Select
 
        End If
 
    End Sub
 
 
    Private Sub FilterGrid(ByVal strFilter As String)
        Dim ds As DataSet = GetData()
 
        Dim dvFilter As DataView = ds.Tables(0).DefaultView
        dvFilter.RowFilter = strFilter
 
        grdShiftObservation.DataSource = dvFilter.ToTable()
        grdShiftObservation.DataBind()
    End Sub


I know dvFilter.ToTable() at this point shows me say 5 rows filtered but when the grid is displayed, it shows no results.

what am I doing wrong? How else can I show the filtered results? I am trying to fix lack of support on the control which does not filter datetime values with date only specified hence the customisation above.

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 05 Apr 2012, 09:54 PM
Hi Ahmed,

I have noticed that my colleague Marin have already answered to the other forum thread that you have opened on the same topic. To avoid duplicate posts I would suggest that you continue your communication there.

Greetings,
Pavlina
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.
Tags
Grid
Asked by
Ahmed Ilyas
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or