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

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

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

Visual Basic (Declaration)
Public Shared Function Eval ( _
    container As Object, _
    expression As String, _
    format As String _
) As String
Visual Basic (Usage)
Dim container As Object
Dim expression As String
Dim format As String
Dim returnValue As String

returnValue = DataBinder.Eval(container, _
    expression, format)
C#
public static string Eval(
    Object container,
    string expression,
    string format
)
Visual C++
public:
static String^ Eval(
    Object^ container, 
    String^ expression, 
    String^ format
)
JScript
public static function Eval(
    container : Object, 
    expression : String, 
    format : String
) : String

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.
format
Type: System..::.String
A .NET Framework format string (like those used by String..::.Format) that converts the Object instance returned by the data-binding expression to a String object.

Return Value

Type: System..::.String
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.

NoteNote:

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 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 to 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 server controls. The format parameter contains an expression that formats the number as a locale-specific currency string.

Visual Basic
<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}") %>
C#
<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}") %>
JScript
<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}") %>
Platforms

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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Other Resources

Tags :


Page view tracker