I am getting a problem related to the date format in ASPxGridView.
I have a application in which i am using AspxGridView. I have a column of type combo box which holds the date values. The column is as
< dxwgv:GridViewDataComboBoxColumn Caption="SERVICE MONTH" Name="ServiceMonthComboBox" Visible=true VisibleIndex="1" FieldName="ServiceMonth">
< EditFormSettings VisibleIndex=1 Visible="false" />< CellStyle HorizontalAlign=Right />
< PropertiesComboBox Style-Font-Names="Verdana" Style-Font-Size="X-Small" TextField="ServiceMonth" ValueField="ServiceMonth">
< Style Font-Names="Verdana" Font-Size="X-Small">< /Style>
< /PropertiesComboBox>< EditFormCaptionStyle ForeColor="Maroon" />
< /dxwgv:GridViewDataComboBoxColumn>
Here, ServiceMonth is of DateTime Type.
At Page_Load event i m using the following code to bind the date data with filter.
GridViewDataComboBoxColumn serviceMonthComboBox = CarHireExchangeGroupSummaryGridView.Columns["ServiceMonthComboBox"] as GridViewDataComboBoxColumn;
serviceMonthComboBox.PropertiesComboBox.ValueType = typeof(DateTime);
serviceMonthComboBox.PropertiesComboBox.Items.Clear();
var serviceMonths = (from item in Presenter.CurrentModel.CarHireExchangeGroupSummaryRecords
select (item.ServiceMonth)).Distinct();
foreach (var serviceMonth in serviceMonths)
{
serviceMonthComboBox.PropertiesComboBox.Items.Add(serviceMonth.ToString("MM/yyyy").Trim(), serviceMonth.ToString("MM/yyyy"));
}
Here, i am binding that combo box with all the distinct ServiceMonth in my records.
Now, i want that, as user filter records using any ServiceMonth, then records should get filter. For that, I have used OnProcessColumnAutoFilter event as follows:
protected void CarHireExchangeGroupSummaryGridView_OnProcessColumnAutoFilter(object sender, ASPxGridViewAutoFilterEventArgs e)
{
if (e.Kind == GridViewAutoFilterEventKind.CreateCriteria)
{
switch (e.Column.FieldName)
{
case "ServiceMonth":
if (!string.IsNullOrEmpty(e.Value))
{
((OperandValue)((BinaryOperator)e.Criteria).RightOperand).Value = Convert.ToDateTime(e.Value.ToString());
}
break;
}
}
}
Now, my problem is that, the value i got is something like this: "Wed Dec 1 00:00:00 CST 2010", now, when i am trying to convert this into DateTime as above code, its giving me the error that "Input string in not in proper DateTime format"
Can you please tell me the reason for this and the way through which i can solve my problem.