For various reasons I initialize datetime fields in a SQL 2005 table to 0 instead of NULL, meaning the fields will show something like '1900-01-01' in a gridview with AutoGeneratedFields.
To get rid of these I use the following code in the Gridviews RowDataBound event:
If e.Row.RowType = DataControlRowType.DataRow
Then
begin
for I := 0 to e.Row.Cells.Count - 1 do
begin
if (pos(InitDateStr,e.Row.Cel
ls[i].text
) > 0) then e.Row.Cells[i].text := '';
end;
end;
It works nicely... but for cells of all types. Not just datetime cells. It means it also empties a stringcell, should the content happen to include the text '01-01-1900' (format depending of the language settings).
So, how can I tell if a cell is bound to a datetime / smalldatetime field in the SQL DB, to only clearing the right cells ?
Start Free Trial