Hi All,
I have a datagrid which has few columns that are of the datetime type. I wanted to format these columns so that it will only display the date. The code below works fine when there is dates in the sql database, however it prompts an error if the field is null.. Please help..
Private Sub dgRecords_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgRecords.ItemDataBound
Dim str10 As String = e.Item.Cells(10).Text.Trim
Dim str11 As String = e.Item.Cells(11).Text.Trim
If e.Item.ItemType = ListItemType.AlternatingItem Or _
e.Item.ItemType = ListItemType.Item Then
If e.Item.Cells(10).Text <> "1/01/1900 12:00:00 AM" Then
e.Item.Cells(10).Text = str10.Substring(0, 10)
Else
e.Item.Cells(10).Text = " "
End If
If e.Item.Cells(11).Text <> "1/01/1900 12:00:00 AM" Then
e.Item.Cells(11).Text = str11.Substring(0, 10)
Else
e.Item.Cells(11).Text = " "
End If
End If
End Sub