1

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に変換しようとすると、エラーが発生します「入力文字列が適切な DateTime 形式ではありません」

この問題の理由と、私の問題を解決する方法を教えてください。

4

1 に答える 1

1

PropertiesComboBox.ValueType を System.DateTime に設定して、AutoFilterRow の ASPxComboBox エディターがそのアイテムの値を DateTime 値に変換するように強制します。

<PropertiesComboBox ... ValueType="System.DateTime"></PropertiesComboBox>
于 2011-05-18T20:12:15.377 に答える