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

[Solved] GridDateTimeColumn filter date format

4 Answers 719 Views
Grid
This is a migrated thread and some comments may be shown as answers.
FreshOne
Top achievements
Rank 1
FreshOne asked on 31 Jan 2010, 02:50 PM
hi all,

i'm using GridDateTimeColumn in a grid, the DataFormatString is set to "{0:d/M/yyyy}", the problem is that the filter don't apply that DataFormatString. For example; i have a date in the grid displayed like this 10/1/2009, but if i type 10/1/2009 in the filter box i get "No records to display", because it's not taking the d/M/yyyy format.

how can i modify the DataFormatString for the filter??

thnx in advance

            <telerik:GridDateTimeColumn HeaderText="Start Date" SortExpression="startDate" UniqueName="startDate" AutoPostBackOnFilter="true" DataField="startDate" 
                FilterControlWidth="110px" PickerType="DatePicker" DataFormatString="{0:d/M/yyyy}">  
            </telerik:GridDateTimeColumn>  

4 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 01 Feb 2010, 11:17 AM
Hello FreshOne,

 In order to achieve this scenario, obtain a reference to the filter box of the column in the ItemCreated event, and set the DateFormat mask for the date input control:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
    {
        RadDatePicker picker = ((GridFilteringItem)e.Item)["DateTimeColumn"].Controls[0] as RadDatePicker;
        if (picker != null)
        {
            picker.DateInput.DateFormat = "d/M/yyyy";
        }
    }
}

I hope this helps.

Best wishes,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
FreshOne
Top achievements
Rank 1
answered on 01 Feb 2010, 02:36 PM
hi Tsvetoslav,
thnx for ur reply i tried wht u have suggested, i just converted it to vb, but still there is a problem. when i type "3/1/2009" for example in the filter box the grid loads, then wht i typed turns into "1/3/2009"..wht could be the problem??

here is my code:
    Private Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated  
        If TypeOf e.Item Is GridFilteringItem Then 
            Dim picker As RadDatePicker = TryCast(DirectCast(e.Item, GridFilteringItem)("startDate").Controls(0), RadDatePicker)  
            If picker IsNot Nothing Then 
                picker.DateInput.DateFormat = "d/M/yyyy" 
            End If 
        End If 
    End Sub 
0
Shinu
Top achievements
Rank 2
answered on 02 Feb 2010, 08:30 AM
Hi,

You need to set the DispalyDateFormat along with the DateFormat to the required format pattern as shown below:

C#
 if (e.Item is GridFilteringItem)  
        {  
            RadDatePicker picker = ((GridFilteringItem)e.Item)["DateTimeColumn"].Controls[0] as RadDatePicker;  
            if (picker != null)  
            {  
                picker.DateInput.DisplayDateFormat = "d/M/yyyy";  
                picker.DateInput.DateFormat = "d/M/yyyy";  
            }  
        }   

Thanks,
Shinu
0
FreshOne
Top achievements
Rank 1
answered on 02 Feb 2010, 09:21 AM
hi Shinu,
thnx for ur reply..i don't know why but that didn't work too

but it works without all DateFormat things by setting globalization to en-GB in web.config:
<globalization culture="en-GB" /> 

or in page load:

System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-GB")   
System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("en-GB"

 


Thnx all

Tags
Grid
Asked by
FreshOne
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
FreshOne
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or