This documentation is archived and is not being maintained.

XPathBinder Class

Provides support for rapid application development (RAD) designers to parse data-binding expressions that use XPath expressions. This class cannot be inherited.

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

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class XPathBinder

You can use the overloaded Eval method of this class to bind to the result of an XPath expression executed against an object that implements the IXPathNavigable interface, such as an XmlNode. You can use the Select method to retrieve the results of an XPath expression executed against an IXPathNavigable object as an IEnumerable list of nodes. This list of nodes can be enumerated directly or assigned to the DataSource property of a list control, such as a Repeater or DataList.

You can use a simplified version of data-binding syntax when using the XPathBinder methods declaratively. Instead of calling XPathBinder.Eval(Container.DataItem, xpath) you can use XPath(xpath). Similarly, instead of calling XPathBinder.Select(Container.DataItem, xpath), you can use XPathSelect(xpath) to retrieve an IEnumerable set of nodes. When using this simplified syntax, the Eval and Select methods assume a default Container.DataItem context object.

For more information about data binding to ASP.NET server controls, see Data-Binding Expression Syntax.

The following code example demonstrates how to use an XmlDataSource control with a templated Repeater control to display XML data. This example has two parts:

  • A Web Forms page that displays XML data.

  • An XML file that contains the data.

The first part of the example shows a Web Forms page that displays XML data accessed through an XmlDataSource control. A Repeater control uses simplified Eval(Object, String) method syntax to bind to data items within the XML document that the XmlDataSource represents. It uses the Select(Object, String) method to retrieve an IEnumerable list and assign it as a late-bound DataSource property for the Repeater control.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
  <head runat="server">
    <form id="form1" runat="server">
        DataFile="order.xml" />

      <asp:Repeater ID="Repeater1"
                <td>Ship To</td>
            <h3>Order Summary</h3>
            <asp:Repeater ID="Repeater2"
                     <b><%#XPath("@dept")%></b> -
                         <%#XPath(".")%><br />
            <hr />


The second example provides the XML file, Order.xml, that is used as the source of the data displayed in the Web Forms page defined above.

<?xml version="1.0" encoding="iso-8859-1"?>
      <customer id="12345" />
      <transaction id="12345" />
        <address1>1234 Tenth Avenue</address1>
        <item dept="tools">screwdriver</item>
        <item dept="tools">hammer</item>
        <item dept="plumbing">fixture</item>


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

.NET Framework

Supported in: 3.5, 3.0, 2.0