Export (0) Print
Expand All

DataBinder.Eval Method (Object, String)

Evaluates data-binding expressions at run time.

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

public static Object Eval(
	Object container,
	string expression


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.

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.


expression is null 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.

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 Model Binding and Web Forms.

The following examples show how to use the Eval method to bind data to Repeater control. It requires a data class named Product.

public class Product
    public int ProductID { get; set; }
    public string Name { get; set; }
    public double Price { get; set; }

The code-behind file loads test data and binds that data to a Repeater control.

public partial class ShowProducts : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        var products = new List<Product>();
        products.Add(new Product() { ProductID = 1, Name = "Bike", Price = 150.00 });
        products.Add(new Product() { ProductID = 2, Name = "Helmet", Price = 19.99 });
        products.Add(new Product() { ProductID = 3, Name = "Tire", Price = 10.00 });

        ProductList.DataSource = products;

In the declarative syntax for the Repeater control, you use the Eval method with Container.DataItem for the container parameter.

<asp:Repeater ID="ProductList" runat="server">
        <%# DataBinder.Eval(Container.DataItem, "Name") %> for only <%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}") %>
        <br />
        <a href='<%# DataBinder.Eval(Container.DataItem, "ProductID", "details.asp?id={0}") %>'>See Details</a>
        <br />
        <br />

Or, you can call Eval function and not include the container parameter.

<asp:Repeater ID="ProductList" runat="server">
        <%# Eval("Name") %> for only <%# Eval("Price", "{0:c}") %>
        <br />
        <a href='<%# Eval("ProductID", "details.asp?id={0}") %>'>See Details</a>
        <br />
        <br />

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

© 2014 Microsoft