开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜