Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
370
Format a column with hour
posted

Hello, 

I have a WebDataGrid with AutoGenerateColumns=False.

Columns are generated at runtime cycling on columns of a DataTable.

DataTable can be different each time.

Fields of the DataTable, in some cases can contain DateTime fileds comming from database but in the field really is stored only the time. For example, in database is stored: 1899-12-30 08:32:21

During the InitializeRow, I would like to format this column as HH:mm.

I'm trying this code but without success (keep in mind that it is not a BoundDataField but is simply a GridField):

Protected Sub GrdList_InitializeRow(sender As Object, e As Infragistics.Web.UI.GridControls.RowEventArgs) Handles GrdList.InitializeRow

If e.Row.Index = 0 Then

For i = 0 To e.Row.Items.Count - 1
If e.Row.Items(i).Column.Type = System.Type.GetType("System.DateTime") Then
Dim field As GridField = e.Row.Items(i).Column
Dim s As DateTime
If Not DBNull.Value.Equals(e.Row.Items(i).Value) Then
s = e.Row.Items(i).Value

If Not (s.TimeOfDay = TimeSpan.Zero) Then

field.FormatValue("HH:mm")

End If

End If
End If
Next

End If

End Sub

Thanks