DataBinder.Eval Method (Object, String) (System.Web.UI)

Switch View :
ScriptFree
.NET Framework Class Library
DataBinder.Eval Method (Object, String)

Evaluates data-binding expressions at run time.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)
Syntax

Visual Basic
Public Shared Function Eval ( _
	container As Object, _
	expression As String _
) As Object
C#
public static Object Eval(
	Object container,
	string expression
)
Visual C++
public:
static Object^ Eval(
	Object^ container, 
	String^ expression
)
F#
static member Eval : 
        container:Object * 
        expression:string -> Object 

Parameters

container
Type: System.Object
The object reference against which the expression is evaluated. This must be a valid object identifier in the page's specified language.
expression
Type: System.String
The navigation path from the container object to the public property value to be placed in the bound control property. This must be a string of property or field names separated by periods, such as Tables[0].DefaultView.[0].Price in C# or Tables(0).DefaultView.(0).Price in Visual Basic.

Return Value

Type: System.Object
An Object instance that results from the evaluation of the data-binding expression.
Exceptions

Exception Condition
ArgumentNullException

expression is null or is an empty string after trimming.

Remarks

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.

Note Note

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.

Examples

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.

Visual Basic


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



C#


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



Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference

Other Resources

Community Content

Tim Golisch
The better way
This MSDN article talks about the better way of doing Data Binding (alternatives to the Eval() method).  http://msdn.microsoft.com/en-us/library/ff647787.aspx#scalenetchapt06_topic13

Jon_AP
Define "Standard ASP.NET data-binding syntax"
"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."

What is the standard ASP.NET data-binding syntax that we should be using instead?  Should we replace this:

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

with any of these:

<%# DataBinder.GetPropertyValue (Container.DataItem, "Price") %>

<%# Eval ("Price") %>

or is there some other way.  

Thanks!