Back to Devexpress

GridViewDataTimeEditColumn Class

aspnet-devexpress-dot-web-6c6de65e.md

latest5.0 KB
Original Source

GridViewDataTimeEditColumn Class

A data column that displays DateTime values.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public class GridViewDataTimeEditColumn :
    GridViewEditDataColumn
vb
Public Class GridViewDataTimeEditColumn
    Inherits GridViewEditDataColumn

Remarks

GridViewDataTimeEditColumn objects represent data columns used to display and edit time portions of data taken from DateTime data fields. The column editor’s settings can be accessed and customized using the GridViewDataTimeEditColumn.PropertiesTimeEdit property.

To learn more, see Data Columns.

Display a TimeSpan value in a column

To display a TimeSpan values in a column, hide the original column bound to the DateTime field and use an extra Unbound Column to perform the conversion between TimeSpan and DateTime types.

aspx
<dx:ASPxGridView ID="ASPxGridView1" runat="server"  
    OnRowInserting="ASPxGridView1_RowInserting"  
    OnRowUpdating="ASPxGridView1_RowUpdating"  
    OnCustomUnboundColumnData="ASPxGridView1_CustomUnboundColumnData"  
    ...  
<Columns>  
    <dx:GridViewDataTimeEditColumn FieldName="Time" Visible="false" />  
    <dx:GridViewDataTimeEditColumn FieldName="UnboundTime" Caption="Time" UnboundType="DateTime">  
        <PropertiesTimeEdit DisplayFormatString="HH:mm:ss" EditFormat="Custom" EditFormatString="HH:mm:ss" />  
    </dx:GridViewDataTimeEditColumn>  
...
csharp
// Display value
protected void ASPxGridView1_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridViewColumnDataEventArgs e) {  
    if (e.Column.FieldName == "UnboundTime") {  
        e.Value = DateTime.MinValue.Add((TimeSpan)e.GetListSourceFieldValue("Time"));  
    }  
}  
// Get value
protected void ASPxGridView1_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) {  
    DateTime date = (DateTime)e.NewValues["UnboundTime"];  
    e.NewValues["Time"] = date.TimeOfDay;  
}  
protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) {  
    DateTime date = (DateTime)e.NewValues["UnboundTime"];  
    e.NewValues["Time"] = date.TimeOfDay;  
}
vb
' Display value
Protected Sub ASPxGridView1_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewColumnDataEventArgs)  
    If e.Column.FieldName = "UnboundTime" Then  
        e.Value = Date.MinValue.Add(CType(e.GetListSourceFieldValue("Time"), TimeSpan))  
    End If  
End Sub  
' Get value
Protected Sub ASPxGridView1_RowInserting(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataInsertingEventArgs)  
    Dim _date As Date = CDate(e.NewValues("UnboundTime"))  
    e.NewValues("Time") = _date.TimeOfDay  
End Sub  
Protected Sub ASPxGridView1_RowUpdating(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataUpdatingEventArgs)  
    Dim _date As Date = CDate(e.NewValues("UnboundTime"))  
    e.NewValues("Time") = _date.TimeOfDay  
End Sub

Implements

IStateManager

IPropertiesOwner

IExpressionsAccessor

IDataSourceViewSchemaAccessor

IFilterablePropertyInfo

IWebGridDataColumn

IWebGridColumn

Inheritance

Object StateManager CollectionItem WebColumnBase GridViewColumn GridViewDataColumn GridViewEditDataColumn GridViewDataTimeEditColumn

See Also

GridViewDataTimeEditColumn Members

Grid View

DevExpress.Web Namespace