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

How to do filtering on datecolumn in dd/mm/yyyy

3 Answers 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Krishna
Top achievements
Rank 1
Krishna asked on 06 Sep 2010, 03:04 PM
Dear Telerik Team

Could you please suggest me how to do filtering in radgrid for a date colum.

i want to filter the date on dd/mm/yyyy.

Please find the below code.

Thanks and Regards
Kishore

aspx source

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CustomerDetails.aspx.cs"
    Inherits="Presentation_Global_CutomerDetails" %>

<%@ Register Assembly="RadAjax.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="radG" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Anand Motors</title>
    <link rel="stylesheet" href="../../Presentation/Global/Style/PMSStyle.css" type="text/css" />
    <style type="text/css">
    .radgrid table.ragrid  tr  td
{
     padding: 0  !important;
     font-size: 25pt;
     font-family: verdana;
}
    </style>
</head>
<body style="margin-left: auto;">
    <form id="form1" runat="server">
        <radG:RadScriptManager ID="ScriptManager" runat="server">
        </radG:RadScriptManager>
        <radG:RadAjaxManager ID="RadAjaxManager2" runat="server">
            <AjaxSettings>
                <radG:AjaxSetting AjaxControlID="RadGrid2">
                    <UpdatedControls>
                        <radG:AjaxUpdatedControl ControlID="RadGrid2" />
                    </UpdatedControls>
                </radG:AjaxSetting>
            </AjaxSettings>
        </radG:RadAjaxManager>
        <radG:RadCodeBlock ID="RadCodeBlock1" runat="server">

            <script language="javascript" type="text/javascript">
           
                function ShowMsg()
                {
                    var sMsg = '';
                    if (sMsg != '')
                        alert(sMsg);
                }
            </script>

        </radG:RadCodeBlock>
        <table cellpadding="1" cellspacing="0" b width="100%" border="0">
            <tr>
                <td align="center" style="width: 100%">
                    <radG:RadGrid ID="RadGrid1" runat="server" GridLines="None" AutoGenerateColumns="False"
                        Skin="Black" Width="100%" AllowPaging="True" PageSize="20" AllowFilteringByColumn="True"
                        AllowSorting="true" OnPreRender="RadGrid1_PreRender" OnItemDataBound="RadGrid1_ItemDataBound1"
                        OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemDataBound">
                        <MasterTableView CommandItemDisplay="Bottom" Font-Size="Small" Font-Names="Tahoma"
                            DataKeyNames="AgreementId">
                            <FilterItemStyle HorizontalAlign="left" />
                            <HeaderStyle Font-Names="Tahoma" />
                            <HeaderStyle Font-Size="XX-Large" />
                            <ItemStyle BackColor="#000000" Height="20px" />
                            <CommandItemStyle HorizontalAlign="Left" />
                            <Columns>
                                <radG:GridBoundColumn Display="True" ShowFilterIcon="False" UniqueName="" HeaderText="Cust Name"
                                    DataField="CustomerName" CurrentFilterFunction="contains" AutoPostBackOnFilter="true">
                                    <HeaderStyle HorizontalAlign="left" />
                                    <ItemStyle Width="300px" />
                                </radG:GridBoundColumn>
                                <radG:GridBoundColumn Display="false" ShowFilterIcon="False" UniqueName="AgreementId"
                                    HeaderText="Agmt ID" DataField="AgreementId" CurrentFilterFunction="contains"
                                    AutoPostBackOnFilter="true">
                                    <HeaderStyle HorizontalAlign="left" />
                                    <ItemStyle Width="30px" />
                                </radG:GridBoundColumn>
                                <radG:GridBoundColumn Display="True" ShowFilterIcon="False" UniqueName="AgreementNumber"
                                    HeaderText="Agmt Num" DataField="AgreementNumber" CurrentFilterFunction="contains"
                                    AutoPostBackOnFilter="true">
                                    <HeaderStyle HorizontalAlign="left" />
                                    <ItemStyle Width="30px" />
                                </radG:GridBoundColumn>
                                <radG:GridDateTimeColumn PickerType="DatePicker" EditFormColumnIndex="0" DataField="AgreementDate"
                                    HeaderText="Agmt Date" SortExpression="AgreementDate" UniqueName="AgreementDate"
                                    AllowFiltering="false" DataFormatString="{0:dd-MM-yyyy}">
                                </radG:GridDateTimeColumn>
                               
                                <radG:GridBoundColumn Display="True" ShowFilterIcon="False" UniqueName="VehicleName"
                                    HeaderText="Vehicle" DataField="VehicleName" CurrentFilterFunction="contains"
                                    AutoPostBackOnFilter="true">
                                    <HeaderStyle HorizontalAlign="left" />
                                    <ItemStyle Width="80px" />
                                </radG:GridBoundColumn>
                                <radG:GridBoundColumn Display="True" ShowFilterIcon="False" UniqueName="FinanceAmount"
                                    HeaderText="F Amount" DataField="FinanceAmount" CurrentFilterFunction="contains"
                                    AutoPostBackOnFilter="true">
                                    <HeaderStyle HorizontalAlign="left" />
                                    <ItemStyle Width="30px" />
                                </radG:GridBoundColumn>
                                <radG:GridBoundColumn Display="True" ShowFilterIcon="False" UniqueName="CustomerMobilePhone"
                                    HeaderText="Mobile" DataField="CustomerMobilePhone" CurrentFilterFunction="contains"
                                    AutoPostBackOnFilter="true">
                                    <HeaderStyle HorizontalAlign="left" />
                                    <ItemStyle Width="30px" />
                                </radG:GridBoundColumn>
                                <radG:GridBoundColumn Display="True" ShowFilterIcon="False" UniqueName="CustomerOfficePhone1"
                                    HeaderText="Office" DataField="CustomerOfficePhone1" CurrentFilterFunction="contains"
                                    AutoPostBackOnFilter="true">
                                    <HeaderStyle HorizontalAlign="left" />
                                    <ItemStyle Width="30px" />
                                </radG:GridBoundColumn>
                                <radG:GridBoundColumn Display="True" ShowFilterIcon="False" UniqueName="ResidencePhone1"
                                    HeaderText="Res" DataField="ResidencePhone1" CurrentFilterFunction="contains"
                                    AutoPostBackOnFilter="true">
                                    <HeaderStyle HorizontalAlign="left" />
                                    <ItemStyle Width="30px" />
                                </radG:GridBoundColumn>
                                <radG:GridTemplateColumn  HeaderStyle-Width="20px" AllowFiltering="False" UniqueName="editHyperlink">
                                    <ItemTemplate>
                                        <tt class="bodytxt">
                                            <asp:ImageButton ID="btnedit" AlternateText="Edit" ImageUrl="../../Presentation/Global/Images/toolbar/edit.gif"
                                                runat="server" />
                                    </ItemTemplate>
                                    <ItemStyle Width="20px" />
                                </radG:GridTemplateColumn>
                                <radG:GridTemplateColumn HeaderStyle-Width="20px" AllowFiltering="False" UniqueName="editHyperlink">
                                    <ItemTemplate>
                                        <tt class="bodytxt">
                                            <asp:ImageButton ID="btnDelete" CommandName="Delete" AlternateText="Delete" ImageUrl="../../Presentation/Global/Images/toolbar/Delete.gif"
                                                runat="server" />
                                    </ItemTemplate>
                                    <ItemStyle Width="20px" />
                                </radG:GridTemplateColumn>
                            </Columns>
                            <CommandItemTemplate>
                                <div>
                                    <asp:Image ID="Image1" ImageUrl="../../Presentation/Global/Images/toolbar/AddRecord.gif"
                                        runat="Server" />
                                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Presentation/Customer/AddEditCustomer.aspx"
                                        Font-Underline="true">Add New Customer</asp:HyperLink>
                                </div>
                            </CommandItemTemplate>
                        </MasterTableView>
                        <ClientSettings EnableRowHoverStyle="true" AllowColumnsReorder="true" ReorderColumnsOnClient="true">
                            <Resizing AllowRowResize="False" EnableRealTimeResize="True" ResizeGridOnColumnResize="True"
                                AllowColumnResize="True"></Resizing>
                        </ClientSettings>
                    </radG:RadGrid>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

aspx.cs code behind

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;

public partial class Presentation_Global_CutomerDetails : System.Web.UI.Page
{
    DataTable dtCustInfo;
    MyWebsite.BusinessRule.CustomerInfo custInfo;
    public string sMsg = null;
    protected void Page_Load(object sender, EventArgs e)
    {

        sMsg = Request.QueryString["msg"];
       
    }
    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {

        custInfo = new MyWebsite.BusinessRule.CustomerInfo();
        if (custInfo.getCustomerInfo(out dtCustInfo) != null)
        {
            this.RadGrid1.DataSource = dtCustInfo;
         
        }
    }
    protected void RadGrid1_PreRender(object sender, System.EventArgs e)
    {
        if (!this.IsPostBack)
        {

            //RadGrid1.ClientSettings.ActiveRowData = String.Format("{0},{1}", RadGrid1.MasterTableView.ClientID, RadGrid1.Items[0].RowIndex);

            this.RadGrid1.MasterTableView.Rebind();
        }
    }
    protected void RadGrid1_ItemDataBound1(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
   
    }

    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.Item is GridDataItem && e.CommandName != "Delete")
        {
            GridDataItem dataItem = (GridDataItem)e.Item;
            ImageButton btn = (ImageButton)dataItem["editHyperlink"].FindControl("btnedit");
            Response.Redirect("../Customer/AddEditCustomer.aspx?AgId=" + dataItem["AgreementId"].Text);
        }
        else if (e.Item is GridDataItem && e.CommandName == "Delete")
        {
            GridDataItem dataItem = (GridDataItem)e.Item;
            string agreementId= dataItem["AgreementId"].Text;
            custInfo = new MyWebsite.BusinessRule.CustomerInfo();
            custInfo.CustId = agreementId.Trim();
            custInfo.deleteCustomerInfo();
            string nothing = agreementId;
        }
    }
}

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 06 Sep 2010, 04:03 PM
Hello Krishna,

How to achieve the desired functionality is demonstrated in the help article below:
Filtering for DateTime bound column with DataFormatString different than mm/dd/yyyy

Regards,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Krishna
Top achievements
Rank 1
answered on 06 Sep 2010, 07:20 PM
Dear Pavlina

Thanks for your immediate help.

But i am sorry to tell you that the link you sent is having compile errors.

Could you please help me in this?

Thanks
Kishore
0
Pavlina
Telerik team
answered on 07 Sep 2010, 08:57 AM
Hello Krishna,

Could you please specify which are the compile errors you received?

Sincerely yours,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Krishna
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Krishna
Top achievements
Rank 1
Share this question
or