Evaluates data-binding expressions at run time.
Public Shared Function Eval ( _ container As Object, _ expression As String _ ) As Object
Dim container As Object Dim expression As String Dim returnValue As Object returnValue = DataBinder.Eval(container, _ expression)
public static Object Eval( Object container, string expression )
public: static Object^ Eval( Object^ container, String^ expression )
public static function Eval( container : Object, expression : String ) : Object
expression is nullNothingnullptra null reference (Nothing in Visual Basic) or is an empty string after trimming.
The value of the expression parameter must evaluate to a public property.
This method is automatically called when you create data bindings in a rapid application development (RAD) designer such as Visual Studio. You can also use it declaratively to simplify casting to a text string. To do so, you use the <%# %> expression syntax, as used in standard ASP.NET data binding.
This method is particularly useful when binding data to controls that are in a templated list.
Because this method performs late-bound evaluation, using reflection at run time, it can cause performance to noticeably slow compared to standard ASP.NET data-binding syntax.
For any of the list Web controls, such as GridView, DetailsView, DataList, or Repeater, container should be Container.DataItem. If you are binding against the page, container should be Page.
The following code example demonstrates how you could use the Eval method declaratively to bind to a Price field. This example uses container syntax that assumes you are using one of the list Web controls.
<%# DataBinder.Eval(Container.DataItem, "Price") %>
<%# DataBinder.Eval (Container.DataItem, "Price") %>
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
Use Explicit casting to avoid databinder.eval (which has the Reflection overhead to type the data),
Strongly type the Container.DataItem in VB.NET as follows
<%# (CType(Container.DataItem, System.Data.DataRowView)("fieldname")) %>
In case of date formats,
<%# (CType(Container.DataItem, System.Data.DataRowView)("datecolumn")).ToShortDateString() %>
The above code is tested in ASP.NET 1.1. http://dotnettipoftheday.org/tips/use-explicit-casting-instead-of-databinder.eval.aspx
Please refer the following blog posts to get more detail and also for C# versions of the code,
http://weblogs.asp.net/rajbk/archive/2004/07/20/what-s-the-deal-with-databinder-eval-and-container-dataitem.aspx
http://weblogs.asp.net/jgalloway/archive/2005/09/20/425687.aspx