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

DateTimeColumn will not filter correctly

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Geoff
Top achievements
Rank 1
Geoff asked on 07 Jul 2016, 05:07 PM

I have a programmatically created radgrid. One Column in the grid is a GridDateTimeColumn. I have allowed filtering on this column, but I can not get it to filter to the exact date. I initially was trying to do format so I could filter on date and time, but I would settle for just the date at this point if it got it working. The column created code is:

 

GridDateTimeColumn bc40 = new GridDateTimeColumn();
dg.MasterTableView.Columns.Add(bc40);
bc40.PickerType = GridDateTimeColumnPickerType.DatePicker;
bc40.DataField = "LaunchDate";
bc40.HeaderText = "LaunchDate";
bc40.UniqueName = "LaunchDate";
bc40.ItemStyle.HorizontalAlign = HorizontalAlign.Left;
bc40.AutoPostBackOnFilter = true;
bc40.DataFormatString = "{0:MM/dd/yyyy}";
bc40.EnableTimeIndependentFiltering = true;
bc40.FilterDateFormat = "MM/dd/yyyy";
bc40.DataType = typeof(System.DateTime);
bc40.Display = true;

 

I have try muliple variations of FormatString, FilterFormats, Disabled TimeIndepence with no such luck. I though it may be looking directly at the grid's format, so I have also added this to my ItemDataBound event:

 

DateTime launchDateTime = DateTime.Parse(item["LaunchDate"].Text.ToString());
string formattedDateTime = String.Format("{0:MM/dd/yyyy}", launchDateTime);
item["LaunchDate"].Text = formattedDateTime;

 

The date on the grid shows up in the format of 01/01/2016. The format in the filter shows up as 01/01/2016. But when the filter of "Equal To" is set, I don't retrieve any records.

 

This filter is a requirement for my application to work properly. Any help would be greatly appreciated.

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 12 Jul 2016, 10:22 AM
Hi Geoff,

Please create the grid structure during Page_Init event handler and add the properties before the grdContingentDevelopment.MasterTableView.Columns.Add(TotalColumn) line:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/creating-a-radgrid-programmatically#creating-a-radgrid-on-page_init

I hope this will prove helpful.


Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Geoff
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or