开发者

when i put (DateTime) in front of a DataBinder.eval what does that do

开发者 https://www.devze.com 2022-12-22 08:07 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号