ASPxGridView - 日期格式问题

发布于 2024-11-08 01:36:08 字数 2445 浏览 1 评论 0原文

我遇到与 ASPxGridView 中的日期格式相关的问题。

我有一个正在使用 AspxGridView 的应用程序。我有一个组合框类型的列,其中包含日期值。 该列如下所示

  < 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>

,ServiceMonth 是 DateTime 类型。

在 Page_Load 事件中,我使用以下代码将日期数据与过滤器绑定。

        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"));
        }

在这里,我将该组合框与我的记录中所有不同的 ServiceMonth 绑定。

现在,我希望,当用户使用任何 ServiceMonth 过滤记录时,记录应该得到过滤。为此,我使用了 OnProcessColumnAutoFilter 事件,如下所示:

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;
                }
            }
}

现在,我的问题是,我得到的值是这样的:“Wed Dec 1 00:00:00 CST 2010”,现在,当我尝试将其转换为DateTime 如上面的代码所示,它给了我错误“输入字符串的日期时间格式不正确”,

您能告诉我原因以及解决问题的方法吗?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫七 2024-11-15 01:36:08

尝试将 PropertiesComboBox.ValueType 设置为 System.DateTime 以强制 AutoFilterRow 的 ASPxComboBox 编辑器将其项目的值转换为 DateTime 值:

<PropertiesComboBox ... ValueType="System.DateTime"></PropertiesComboBox>

Try to set the PropertiesComboBox.ValueType to System.DateTime to force the AutoFilterRow’s ASPxComboBox editor convert Value of its Items to the DateTime values:

<PropertiesComboBox ... ValueType="System.DateTime"></PropertiesComboBox>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文