System.Web.UI.DataBinder.Eval Method

Evaluates data-binding expressions at run time and formats the result as a string.

Syntax

public static string Eval (object container, string expression, string format)

Parameters

container
The object reference against which the expression is evaluated. This must be a valid object identifier in the page's specified language.
expression
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.
format
A .NET Framework format string (like those used by string.Format(string, object)) that converts the object instance returned by the data-binding expression to a string object.

Returns

A string object that results from evaluating the data-binding expression and converting it to a string type.

Remarks

The value of expression must evaluate to a public property.

For more information about format strings in the .NET Framework, see Formatting Overview.

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 convert the object resulting from the data-binding expression to a string. To use the method declaratively, 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:

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. Use this method judiciously, particularly when string formatting is not required.

For any of the list Web controls, such as System.Web.UI.WebControls.GridView, System.Web.UI.WebControls.DetailsView, System.Web.UI.WebControls.DataList, or System.Web.UI.WebControls.Repeater, container should be Container.DataItem. If you are binding against the page, container should be Page.

Starting in .NET Framework 4.5, you can use model binding to simplify some of the tasks that you had to perform through data-binding in earlier versions. For a tutorial series on using model binding with Web Forms, see tp://go.microsoft.com/fwlink/?LinkId=286117.

Requirements

Namespace: System.Web.UI
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0