开发者

asp Eval function

can i save the returning value of eval function in a variable and use it wherever i want? i can开发者_运维知识库 call it just in <asp: .... tags. i can't use them in vb methods. is it possible?


Eval("foo") is a shortcut for DataBinder.Eval(Container.DataItem, "foo"). Container.DataItem contains the actual data you're trying to get at, and the Eval() method simply uses reflection or other means to allow late binding on names.

If you want better compile-time type checking, you can always cast the Container.DataItem to whatever type you want.

You can also re-use DataBinder.Eval() elsewhere, as a shortcut for using Reflection.

Some examples of what you can do are below:

<%# DoSomethingWithData (DataBinder.Eval(Container.DataItem, "Foo")) %>

Sub DoSomethingWithData (Object data)
   SomeProperty = data
   DoSomethingWithData = data
End Sub

<%# DoSomethingWithDataStronglyTyped (Container.DataItem) %>

Sub DoSomethingWithDataStronglyTyped (Object data)
   Dim StronglyTyped as SomeType
   StronglyTyped = DirectCast (data, SomeType)
   DoSomethingWithDataStronglyTyped = DoSomethingElse(StronglyTyped)
End Sub

Sub ExampleOfDataBinderEvalReuse ()

   Dim StronglyTyped as SomeType
   StronglyTyped = GetSomeData()

   ' get "Foo" property of the SomeType class
   DataBinder.Eval(StronglyTyped, "Foo")
End Sub
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜