Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TemplateControl.XPath Method (String)

Evaluates an XPath data-binding expression.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
protected internal Object XPath (
	string xPathExpression
)
protected Object XPath (
	String xPathExpression
)
protected internal function XPath (
	xPathExpression : String
) : Object
Not applicable.

Parameters

xPathExpression

The XPath expression to evaluate. For more information, see XPathBinder.

Return Value

An object that results from the evaluation of the data-binding expression.
Exception typeCondition

InvalidOperationException

The data-binding method can be used only for controls contained on a Page.

The XPath method calls the XPathBinder.Eval method using the GetDataItem method to resolve the IXPathNavigable object reference that the expression is evaluated against.

The following code example demonstrates how to use the XPath method in a Repeater control.

<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>TemplateControl XPath and XPathSelect Example</title>
</head>
<body>
    <h3>TemplateControl XPath Example</h3>
    <form id="form1" runat="server">
    <div>
      <asp:XmlDataSource
        id="XmlDataSource1" 
        runat="server"
        XPath="contacts" 
        DataFile="contacts.xml" />    
      <asp:FormView 
        id="FormView1" 
        runat="server" 
        DataSourceID="XmlDataSource1">
        <ItemTemplate>
          <hr />
          <asp:Repeater 
            id="Repeater1" 
            runat="server" 
            DataSource='<%# XPathSelect("contact") %>' >
            <ItemTemplate>
              Name: <%# XPath("name") %> <br />
              Note: <%# XPath("note") %> <br />
              <hr />
            </ItemTemplate>
          </asp:Repeater>
        </ItemTemplate>
      </asp:FormView>
    </div>
    </form>
</body>
</html>

The following test XML data can be used in the preceding code example.

<contacts>
   <contact id="1">
     <name>contact name 1</name>
     <note>contact note 1</note>
   </contact>
   <contact id="2">
     <name>contact name 2</name>
     <note>contact note 2</note>
   </contact>
</contacts>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.