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
I hope this snippet of code for UI grid view control I googled can be a reference of solution to your time problem.
GridDateTimeColumn dateTimeColumn1 = new GridDateTimeColumn();dateTimeColumn1.Name = "DateTimeColumn";dateTimeColumn1.HeaderText = "Set date";dateTimeColumn1.FieldName = "SetDate";dateTimeColumn1.Format = DateTimePickerFormat.Custom;dateTimeColumn1.CustomFormat = "t";