Radgrid filtering on datetime column with onkeypress to do filtering

2 posts, 0 answers
  1. Anthony
    Anthony avatar
    6 posts
    Member since:
    Aug 2010

    Posted 17 Feb 2011 Link to this post

    I have attached a simple project that demonstrates the issue i am having. I want a user to be able to filter using the contains function by any columns with an enter key press (I have already done this thanks to a previous support ticket, thank you telerik support). However, now my issue is that i want the user to be able to filter using the equal to function on the enter key press for date columns which i have also been able to figure out how to do. My only issue is that when the user types in letters or an invalid date, the filter comes back with an invalid date error. I need it to validate the date before it filters the column so there cannot be an error. I noticed that if i type in an invalid date then actually go in and click equal to filter function then it will not filter until i have changed the date to a valid date and clicked the filter function again. I would like to achieve this same functionality but using the enter key press. Thank you.

    Here is my source code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
     
    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server"  />
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <%--Needed for JavaScript IntelliSense in VS2010--%>
                <%--For VS2008 replace RadScriptManager with ScriptManager--%>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
     
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="rlpProgress">
        <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="grid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="grid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="grid2">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="grid2" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="grid3">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="grid3" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="grid4">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="grid4" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
         
        <telerik:RadAjaxLoadingPanel ID="rlpProgress" runat="server" Skin="Default" BackgroundPosition="Center"/>
     
        <telerik:RadTabStrip ID="RadTabStrip1" runat="server" MultiPageID="rmp1">
            <Tabs>
                <telerik:RadTab Text="tab 1" Value="1" PageViewID="rpv1" Selected="true"></telerik:RadTab>
                <telerik:RadTab Text="tab 2" Value="2" PageViewID="rpv2"></telerik:RadTab>
                <telerik:RadTab Text="tab 3" Value="3" PageViewID="rpv3"></telerik:RadTab>
                <telerik:RadTab Text="tab 4" Value="4" PageViewID="rpv4"></telerik:RadTab>
            </Tabs>
        </telerik:RadTabStrip>
         
         
        <telerik:RadMultiPage ID="rmp1" runat="server">
            <telerik:RadPageView ID="rpv1" runat="server" Selected="true">
            <h1>Grid 1</h1>
                <telerik:RadGrid ID="grid1" runat="server"
                    AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True">
                    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                    </HeaderContextMenu>
                    <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID"
                        >
                        <CommandItemSettings ExportToPdfText="Export to Pdf" />
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="ID" DataType="System.Int32"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True"
                                SortExpression="ID" UniqueName="ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Name"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Name column" HeaderText="Name"
                                SortExpression="Name" UniqueName="Name">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Address"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Address column" HeaderText="Address"
                                SortExpression="Address" UniqueName="Address">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="City"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter City column" HeaderText="City"
                                SortExpression="City" UniqueName="City">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="State"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter State column" HeaderText="State"
                                SortExpression="State" UniqueName="State">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ZipCode"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter ZipCode column" HeaderText="ZipCode"
                                SortExpression="ZipCode" UniqueName="ZipCode">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PhoneNo"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter PhoneNo column" HeaderText="PhoneNo"
                                SortExpression="PhoneNo" UniqueName="PhoneNo">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Email"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Email column" HeaderText="Email"
                                SortExpression="Email" UniqueName="Email">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Comments"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Comments column" HeaderText="Comments"
                                SortExpression="Comments" UniqueName="Comments">
                            </telerik:GridBoundColumn>
                            <telerik:GridDateTimeColumn DataField="DateEntered"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter DateEntered column" HeaderText="DateEntered"
                                ReadOnly="True" SortExpression="DateEntered" UniqueName="DateEntered" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}">
                            </telerik:GridDateTimeColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <GroupingSettings CaseSensitive="false" />
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                </telerik:RadGrid>
            </telerik:RadPageView>
             
             
             
             
            <telerik:RadPageView ID="rpv2" runat="server">
                <h1>Grid 2</h1>
                <telerik:RadGrid ID="grid2" runat="server"
                    AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True">
                    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                    </HeaderContextMenu>
                    <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID"
                        >
                        <CommandItemSettings ExportToPdfText="Export to Pdf" />
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="ID" DataType="System.Int32"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True"
                                SortExpression="ID" UniqueName="ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Name"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Name column" HeaderText="Name"
                                SortExpression="Name" UniqueName="Name">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Address"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Address column" HeaderText="Address"
                                SortExpression="Address" UniqueName="Address">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="City"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter City column" HeaderText="City"
                                SortExpression="City" UniqueName="City">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="State"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter State column" HeaderText="State"
                                SortExpression="State" UniqueName="State">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ZipCode"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter ZipCode column" HeaderText="ZipCode"
                                SortExpression="ZipCode" UniqueName="ZipCode">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PhoneNo"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter PhoneNo column" HeaderText="PhoneNo"
                                SortExpression="PhoneNo" UniqueName="PhoneNo">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Email"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Email column" HeaderText="Email"
                                SortExpression="Email" UniqueName="Email">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Comments"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Comments column" HeaderText="Comments"
                                SortExpression="Comments" UniqueName="Comments">
                            </telerik:GridBoundColumn>
                            <telerik:GridDateTimeColumn DataField="DateEntered"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter DateEntered column" HeaderText="DateEntered"
                                ReadOnly="True" SortExpression="DateEntered" UniqueName="DateEntered" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}">
                            </telerik:GridDateTimeColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <GroupingSettings CaseSensitive="false" />
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                </telerik:RadGrid>
            </telerik:RadPageView>
     
             
             
            <telerik:RadPageView ID="rpv3" runat="server">
               <h1>Grid 3</h1>
               <telerik:RadGrid ID="grid3" runat="server"
                    AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True">
                   <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                   </HeaderContextMenu>
                   <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID"
                       >
                       <CommandItemSettings ExportToPdfText="Export to Pdf" />
                       <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                           <HeaderStyle Width="20px" />
                       </RowIndicatorColumn>
                       <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                           <HeaderStyle Width="20px" />
                       </ExpandCollapseColumn>
                       <Columns>
                           <telerik:GridBoundColumn DataField="ID" DataType="System.Int32"  FilterListOptions="VaryByDataType"
                               FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True"
                               SortExpression="ID" UniqueName="ID">
                           </telerik:GridBoundColumn>
                           <telerik:GridBoundColumn DataField="Name"  FilterListOptions="VaryByDataType"
                               FilterControlAltText="Filter Name column" HeaderText="Name"
                               SortExpression="Name" UniqueName="Name">
                           </telerik:GridBoundColumn>
                           <telerik:GridBoundColumn DataField="Address"  FilterListOptions="VaryByDataType"
                               FilterControlAltText="Filter Address column" HeaderText="Address"
                               SortExpression="Address" UniqueName="Address">
                           </telerik:GridBoundColumn>
                           <telerik:GridBoundColumn DataField="City"  FilterListOptions="VaryByDataType"
                               FilterControlAltText="Filter City column" HeaderText="City"
                               SortExpression="City" UniqueName="City">
                           </telerik:GridBoundColumn>
                           <telerik:GridBoundColumn DataField="State"  FilterListOptions="VaryByDataType"
                               FilterControlAltText="Filter State column" HeaderText="State"
                               SortExpression="State" UniqueName="State">
                           </telerik:GridBoundColumn>
                           <telerik:GridBoundColumn DataField="ZipCode"  FilterListOptions="VaryByDataType"
                               FilterControlAltText="Filter ZipCode column" HeaderText="ZipCode"
                               SortExpression="ZipCode" UniqueName="ZipCode">
                           </telerik:GridBoundColumn>
                           <telerik:GridBoundColumn DataField="PhoneNo"  FilterListOptions="VaryByDataType"
                               FilterControlAltText="Filter PhoneNo column" HeaderText="PhoneNo"
                               SortExpression="PhoneNo" UniqueName="PhoneNo">
                           </telerik:GridBoundColumn>
                           <telerik:GridBoundColumn DataField="Email"  FilterListOptions="VaryByDataType"
                               FilterControlAltText="Filter Email column" HeaderText="Email"
                               SortExpression="Email" UniqueName="Email">
                           </telerik:GridBoundColumn>
                           <telerik:GridBoundColumn DataField="Comments"  FilterListOptions="VaryByDataType"
                               FilterControlAltText="Filter Comments column" HeaderText="Comments"
                               SortExpression="Comments" UniqueName="Comments">
                           </telerik:GridBoundColumn>
                           <telerik:GridDateTimeColumn DataField="DateEntered"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter DateEntered column" HeaderText="DateEntered"
                                ReadOnly="True" SortExpression="DateEntered" UniqueName="DateEntered" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}">
                            </telerik:GridDateTimeColumn>
                       </Columns>
                       <EditFormSettings>
                           <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                           </EditColumn>
                       </EditFormSettings>
                   </MasterTableView>
                   <GroupingSettings CaseSensitive="false" />
                   <FilterMenu EnableImageSprites="False">
                   </FilterMenu>
                </telerik:RadGrid>
            </telerik:RadPageView>
     
             
             
            <telerik:RadPageView ID="rpv4" runat="server">
                <h1>Grid 4</h1>
                <telerik:RadGrid ID="grid4" runat="server" 
                    AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True">
                    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                    </HeaderContextMenu>
                    <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID"
                        >
                        <CommandItemSettings ExportToPdfText="Export to Pdf" />
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="ID" DataType="System.Int32"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True"
                                SortExpression="ID" UniqueName="ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Name"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Name column" HeaderText="Name"
                                SortExpression="Name" UniqueName="Name">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Address"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Address column" HeaderText="Address"
                                SortExpression="Address" UniqueName="Address">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="City"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter City column" HeaderText="City"
                                SortExpression="City" UniqueName="City">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="State"
                                FilterControlAltText="Filter State column" HeaderText="State"
                                SortExpression="State" UniqueName="State">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ZipCode"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter ZipCode column" HeaderText="ZipCode"
                                SortExpression="ZipCode" UniqueName="ZipCode">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PhoneNo"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter PhoneNo column" HeaderText="PhoneNo"
                                SortExpression="PhoneNo" UniqueName="PhoneNo">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Email"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Email column" HeaderText="Email"
                                SortExpression="Email" UniqueName="Email">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Comments"  FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Comments column" HeaderText="Comments"
                                SortExpression="Comments" UniqueName="Comments">
                            </telerik:GridBoundColumn>
                            <telerik:GridDateTimeColumn DataField="DateEntered" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter DateEntered column" HeaderText="DateEntered"
                                ReadOnly="True" SortExpression="DateEntered" UniqueName="DateEntered" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}">
                            </telerik:GridDateTimeColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <GroupingSettings CaseSensitive="false" />
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                </telerik:RadGrid>
                 
            </telerik:RadPageView>
        </telerik:RadMultiPage>
       
      
    <telerik:RadButton ID="chkbox" runat="server" ButtonType="ToggleButton" Skin="Web20" Text="Checkbox" ToggleType="CheckBox" Font-Underline="false"></telerik:RadButton>
        
     
     <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
           <script type="text/javascript">
     
               function doFilter(sender, eventArgs, gvwName) {
                   if ((eventArgs.keyCode == 13 || eventArgs.keyCode == 9) && (sender.value != "")) {
                       eventArgs.cancelBubble = true;
                       eventArgs.returnValue = false;
                       if (eventArgs.stopPropagation) {
                           eventArgs.stopPropagation();
                           eventArgs.preventDefault();
                       }
                       var masterTableView = $find(gvwName).get_masterTableView();
                       var index = sender.parentNode.cellIndex;
                       var columns = masterTableView.get_columns();
                       var uniqueName = columns[index].get_uniqueName();
                       var filterFunction = columns[index].get_filterFunction();
                       masterTableView.filter(uniqueName, sender.value, filterFunction);
                   }
               }
     
               function doFilterDate(sender, eventArgs, gvwName, gvwColName) {
                   if ((eventArgs.keyCode == 13 || eventArgs.keyCode == 9) && (sender.value != "")) {
                       eventArgs.cancelBubble = true;
                       eventArgs.returnValue = false;
                       if (eventArgs.stopPropagation) {
                           eventArgs.stopPropagation();
                           eventArgs.preventDefault();
                       }
                       var chkbox = $find('<%=chkbox.ClientID%>');
                       chkbox.focus();
                       var masterTableView = $find(gvwName).get_masterTableView();
                       masterTableView.filter(gvwColName, sender.value, Telerik.Web.UI.GridFilterFunction.EqualTo);
                       this.focus();
                   }
               }
                
               function FilterChanged(sender, eventArgs, gvwName) {
                
                   var active = document.activeElement;
                    
                  if (sender.value == "") {
                       eventArgs.cancelBubble = true;
                       eventArgs.returnValue = false;
                       if (eventArgs.stopPropagation) {
                           eventArgs.stopPropagation();
                           eventArgs.preventDefault();
                       }
                       var masterTableView = $find(gvwName).get_masterTableView();
                        
                       var index = sender.parentNode.cellIndex;
                       var columns = masterTableView.get_columns();
                       var uniqueName = columns[index].get_uniqueName();
                       masterTableView.filter(uniqueName, sender.value, Telerik.Web.UI.GridFilterFunction.NoFilter);
                   }
               }
     
               function FilterChangedDate(sender, eventArgs, gvwName, gvwColName) {
     
                   var active = document.activeElement;
     
                   if (sender.value == "") {
                       eventArgs.cancelBubble = true;
                       eventArgs.returnValue = false;
                       if (eventArgs.stopPropagation) {
                           eventArgs.stopPropagation();
                           eventArgs.preventDefault();
                       }
                       var masterTableView = $find(gvwName).get_masterTableView();
                       masterTableView.filter(gvwColName, sender.value, Telerik.Web.UI.GridFilterFunction.NoFilter);
                   }
               }
            </script>
    </telerik:RadCodeBlock>              
                     
        </form>
    </body>
    </html>
    Imports Telerik.Web.UI
    Imports Telerik.Web
    Imports System.Data.OleDb
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Data.Sql
     
    Partial Class _Default
        Inherits System.Web.UI.Page
     
        Public dbConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/app_data/RadGridFilteringIssue.mdb") & ";User Id=admin;Password=;")
        Public strSQL As String = "SELECT People.ID, People.Name, People.Address, People.City, People.State, People.ZipCode, People.PhoneNo, People.Email, People.Comments, Date As DateEntered FROM People"
     
        Public Sub AddFilterOnKey(ByVal gvwName As String, ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
            Dim gvw As RadGrid = DirectCast(rmp1.FindControl(gvwName), RadGrid)
            Dim ctrl As Control
            If TypeOf e.Item Is GridFilteringItem Then
                Dim fltItem As GridFilteringItem = TryCast(e.Item, GridFilteringItem)
                For Each column As GridColumn In gvw.Columns
                    column.CurrentFilterFunction = GridKnownFunction.Contains
                    ctrl = fltItem(column.UniqueName).Controls(0)
                    If TypeOf ctrl Is TextBox Then
                        Dim box As TextBox = TryCast(ctrl, TextBox)
                        box.Attributes.Add("onkeydown", "doFilter(this,event,'" & gvw.ClientID & "')")
                        box.Attributes.Add("onchange", "FilterChanged(this,event,'" & gvw.ClientID & "')")
                    ElseIf TypeOf ctrl Is RadDatePicker Then
                        Dim datepick As RadDatePicker = TryCast(ctrl, RadDatePicker)
                        Dim dateinput As RadDateInput = TryCast(datepick.DateInput, RadDateInput)
                        dateinput.Attributes.Add("onkeypress", "doFilterDate(this,event,'" & gvw.ClientID & "','" & column.UniqueName & "')")
                        dateinput.Attributes.Add("onchange", "FilterChangedDate(this,event,'" & gvw.ClientID & "','" & column.UniqueName & "')")
                    End If
                Next
            End If
        End Sub
     
        Protected Sub grid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grid1.ItemCreated
            For Each column As GridColumn In grid1.Columns
                If column.CurrentFilterFunction = GridKnownFunction.NoFilter Then
                    If Not column.UniqueName = "Delete" Then
                        column.CurrentFilterFunction = GridKnownFunction.Contains
                    End If
                End If
            Next
            AddFilterOnKey("grid1", sender, e)
        End Sub
     
        Protected Sub grid2_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grid2.ItemCreated
            For Each column As GridColumn In grid2.Columns
                If column.CurrentFilterFunction = GridKnownFunction.NoFilter Then
                    If Not column.UniqueName = "Delete" Then
                        column.CurrentFilterFunction = GridKnownFunction.Contains
                    End If
                End If
            Next
            AddFilterOnKey("grid2", sender, e)
        End Sub
     
     
        Protected Sub grid3_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grid3.ItemCreated
            For Each column As GridColumn In grid3.Columns
                If column.CurrentFilterFunction = GridKnownFunction.NoFilter Then
                    If Not column.UniqueName = "Delete" Then
                        column.CurrentFilterFunction = GridKnownFunction.Contains
                    End If
                End If
            Next
            AddFilterOnKey("grid3", sender, e)
        End Sub
     
        Protected Sub grid4_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grid4.ItemCreated
            For Each column As GridColumn In grid4.Columns
                If column.CurrentFilterFunction = GridKnownFunction.NoFilter Then
                    If Not column.UniqueName = "Delete" Then
                        column.CurrentFilterFunction = GridKnownFunction.Contains
                    End If
                End If
            Next
            AddFilterOnKey("grid4", sender, e)
        End Sub
     
        Protected Sub grid1_SortCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridSortCommandEventArgs) Handles grid1.SortCommand
            DataBindGrid("grid1")
        End Sub
     
        Protected Sub grid1_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grid1.ItemCommand
            If e.CommandName = RadGrid.FilterCommandName Then
                DataBindGrid("grid1")
            End If
        End Sub
     
        Protected Sub grid2_SortCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridSortCommandEventArgs) Handles grid2.SortCommand
            DataBindGrid("grid2")
        End Sub
     
        Protected Sub grid2_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grid2.ItemCommand
            If e.CommandName = RadGrid.FilterCommandName Then
                DataBindGrid("grid2")
            End If
        End Sub
     
        Protected Sub grid3_SortCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridSortCommandEventArgs) Handles grid3.SortCommand
            DataBindGrid("grid3")
        End Sub
     
        Protected Sub grid3_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grid3.ItemCommand
            If e.CommandName = RadGrid.FilterCommandName Then
                DataBindGrid("grid3")
            End If
        End Sub
     
        Protected Sub grid4_SortCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridSortCommandEventArgs) Handles grid4.SortCommand
            DataBindGrid("grid4")
        End Sub
     
        Protected Sub grid4_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grid4.ItemCommand
            If e.CommandName = RadGrid.FilterCommandName Then
                DataBindGrid("grid4")
            End If
        End Sub
     
        Public Sub DataBindGrid(ByVal gvwName As String)
            Dim gvw As RadGrid = DirectCast(rmp1.FindControl(gvwName), RadGrid)
     
            Dim reader As OleDbDataReader
            Dim cmd As New OleDbCommand(strSQL, dbConn)
     
            Dim dt As New DataTable
            dbConn.Open()
            Try
                reader = cmd.ExecuteReader
                If reader.HasRows Then
                    dt.Load(reader)
                End If
            Catch ex As Exception
            Finally
                If Not dbConn Is Nothing Then dbConn.Close()
            End Try
     
            gvw.DataSource = dt
            gvw.DataBind()
        End Sub
     
        Public Sub GetDataSource(ByVal gvwName As String)
            Dim gvw As RadGrid = DirectCast(rmp1.FindControl(gvwName), RadGrid)
     
            Dim reader As OleDbDataReader
            Dim cmd As New OleDbCommand(strSQL, dbConn)
     
            Dim dt As New DataTable
            dbConn.Open()
            Try
                reader = cmd.ExecuteReader
                If reader.HasRows Then
                    dt.Load(reader)
                End If
            Catch ex As Exception
            Finally
                If Not dbConn Is Nothing Then dbConn.Close()
            End Try
     
            gvw.DataSource = dt
        End Sub
     
        Protected Sub grid4_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grid4.NeedDataSource
            GetDataSource("grid4")
        End Sub
     
        Protected Sub grid3_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grid3.NeedDataSource
            GetDataSource("grid3")
        End Sub
     
     
        Protected Sub grid2_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grid2.NeedDataSource
            GetDataSource("grid2")
        End Sub
     
        Protected Sub grid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grid1.NeedDataSource
            GetDataSource("grid1")
        End Sub
    End Class
  2. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 23 Feb 2011 Link to this post

    Hello Anthony,

    In order to implement the desired functionality, I recommend that you use a GridDateTimeColumn with picker type DatePicker:
    <telerik:GridDateTimeColumn  PickerType="DatePicker" ... >   </telerik:GridDateTimeColumn>

    I hope this helps.

    Regards,
    Mira
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top