mdProgrammer
Programmer
I have an unbound (dynamic) datagrid which sometimes has a column with a date field that needs to be formatted to show as '1/1/2009' instead of '1/1/2009 12:00:00 AM'. This works, however, it's when I have another column with values like "11-10", "11-11" (these are special code fields that the user understands), the isDate() function treats it as a date. I have the following code in my ItemDataBound event -
It works great until it sees something like '11-10' (even something like 11.10, 11!10, 11~10, etc., will be changed to a date) and turns it into 11/10/2009. For now, I have to add this code for it to work -
Is there another way to do this?
Code:
For i As Integer = 0 To e.Item.Cells.Count - 1
If IsDate(e.Item.Cells(i).Text) Then
Dim dte As Date = e.Item.Cells(i).Text
e.Item.Cells(i).Text = DatePart(DateInterval.Month, dte) & "/" & DatePart(DateInterval.Day, dte) & "/" & DatePart(DateInterval.Year, dte)
End If
Next
It works great until it sees something like '11-10' (even something like 11.10, 11!10, 11~10, etc., will be changed to a date) and turns it into 11/10/2009. For now, I have to add this code for it to work -
Code:
And (e.Item.Cells(i).Text.Length >= 20)
Is there another way to do this?