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 would suggest you to use BoundDataField, which has DataFormatString property responsible for the column's data format.
Please let me know if you have any other questions.
No, is not possible. I have to change all the logic and is not the case after all the work with grid.
Is there a way to format a column even if it is not Bound??
It is not possible to add columns of type GridField to the grid's columns collection. In your InitializeRow event handler access the date column as BoundDataField:
Dim field As BoundDataField = e.Row.Items(i).Column
Then set the DataFormatString to appropriate value.
Hope this helps.
Hi,
I'm just checking If you have any further questions on the matter.