First Check Is the Database column null-able?
You haven't mentioned which version of asp.net framework you are using.
For .net framework >= 3.5, you can use the nullable datatypes i.e. the binding should be with a datetime? field instead of datetime. The error you have mentioned is due the fact that you are trying to bind a null value to a variable of the type, datetime. Use dateime? and your error "Object cannot be cast from DBNull to other types" will be resolved. Or you can do the following in the itemdatabound event:
yourTextBox.value = string.empty
if(((DataRow)e.Item.DataItem)["YourDateField"] != dbnull.value)
{
yourTextBox.value = ((DataRowView)e.Item.DataItem)["YourDateField"] .toString();
}
You haven't mentioned what you are doing for databinding/datasaving. In the data-saving code do the following:
datetime? saveDate = null;
if(!string.isnullorempty( yourTextBox.value))
{
saveDate = converto.datetime( yourTextBox.value);
}
//Use the saveDate for the saving.