when i put (DateTime) in fron开发者_C百科t of a DataBinder.eval what does that do, and what other functions can i put infornt of a databinder??
It will just cast the object returned by the .Eval
method, to the DateTime
type. If casting is impossible, an InvalidCastException
will be thrown. Regarding functions that you can put in front of DataBinder.Eval
, you can put pretty much anything. However, the majority of this won't work.
It is casting the data from object
which Eval
is returning to a DateTime
.
// If the cast fails you will get an exception
DateTime dt = (DataTime)(DataBinder.Eval("yourfield"));
// If the cast fails you will get null.
DateTime? dt = DataBinder.Eval("yourfield") as DateTime?;
// You could also do which will throw an exception if it fails as well.
DateTime dt = Convert.ToDateTime(DataBinder.Eval("yourfield"));
For more information on casting see MSDN.
精彩评论