XPathBinder::Eval Method (Object, String, IXmlNamespaceResolver)
Evaluates XPath data-binding expressions at run time and formats the result as text to be displayed in the requesting browser, using the IXmlNamespaceResolver object specified to resolve namespace prefixes in the XPath expression.
Assembly: System.Web (in System.Web.dll)
public: static Object^ Eval( Object^ container, String^ xPath, IXmlNamespaceResolver^ resolver )
Parameters
- container
- Type: System::Object
The IXPathNavigable object reference that the expression is evaluated against. This must be a valid object identifier in the page's specified language.
- xPath
- Type: System::String
The XPath query from the container to the property value to be placed in the bound control property.
- resolver
- Type: System.Xml::IXmlNamespaceResolver
The IXmlNamespaceResolver object used to resolve namespace prefixes in the XPath expression.
Return Value
Type: System::ObjectA Object that results from the evaluation of the data-binding expression.
You can use the Eval method declaratively if you want to simplify the casting of an XML node to a text string to be displayed in a browser. To do so, you must place the <%# and %> tags, which are also used in standard ASP.NET data binding, around the data-binding expression. The data-binding expression includes the XPath expression and an IXmlNamespaceResolver object to resolve the namespace reference.
For any of the list ASP.NET server controls, such as DataList, DataGrid, or Repeater, the container parameter should be Container.DataItem. If you are binding against the page, the container parameter should be Page.
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 the simplified Eval 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.
The second example provides the XML file, Bookstore2.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"?>
<bookstore>
<genre name="fiction">
<book ISBN="10-861003-324">
<contoso:author xmlns:contoso="http://www.contoso.com">
<contoso:firstname>test</contoso:firstname>
<contoso:lastname>test2</contoso:lastname>
</contoso:author>
<title>The Handmaid's Tale</title>
<price>12.95</price>
<chapters>
<chapter num="1" name="Introduction" />
<chapter num="2" name="Body" />
<chapter num="3" name="Conclusion" />
</chapters>
</book>
</genre>
<genre name="nonfiction">
<book genre="nonfiction" ISBN="1-861001-57-5">
<author>
<firstname>test3</firstname>
<lastname>test4</lastname>
</author>
<title>Pride And Prejudice</title>
<price>24.95</price>
<chapters>
<chapter num="1" name="Introduction" />
<chapter num="2" name="Body" />
<chapter num="3" name="Conclusion" />
</chapters>
</book>
</genre>
</bookstore>
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.