XPathBinder.Eval 方法

定義

在執行階段針對 IXPathNavigable 物件來剖析及評估 XPath 資料繫結運算式。Parses and evaluates an XPath data-binding expression against an IXPathNavigable object at run time.

多載

Eval(Object, String)

評估執行階段的 XPath 資料繫結運算式。Evaluates XPath data-binding expressions at run time.

Eval(Object, String, String)

在執行階段評估 XPath 資料繫結運算式,並將結果格式化成為文字,以顯示於提出要求的瀏覽器中。Evaluates XPath data-binding expressions at run time and formats the result as text to be displayed in the requesting browser.

Eval(Object, String, IXmlNamespaceResolver)

透過使用 IXmlNamespaceResolver 物件 (指定用於解析 XPath 運算式中的命名空間前置詞),在執行階段評估 XPath 資料繫結運算式,並將結果格式化成為文字,以顯示於要求的瀏覽器中。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.

Eval(Object, String, String, IXmlNamespaceResolver)

透過使用 IXmlNamespaceResolver 物件 (指定用於解析 XPath 運算式中的命名空間前置詞),在執行階段評估 XPath 資料繫結運算式,並將結果格式化成為文字,以顯示於要求的瀏覽器中。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.

Eval(Object, String)

評估執行階段的 XPath 資料繫結運算式。Evaluates XPath data-binding expressions at run time.

public:
 static System::Object ^ Eval(System::Object ^ container, System::String ^ xPath);
public static object Eval (object container, string xPath);
static member Eval : obj * string -> obj
Public Shared Function Eval (container As Object, xPath As String) As Object

參數

container
Object

運算式所據以評估的 IXPathNavigable 物件參考。The IXPathNavigable object reference that the expression is evaluated against. 這在網頁的指定語言中必須是有效的物件識別項。This must be a valid object identifier in the page's specified language.

xPath
String

container 到屬性值的 XPath 查詢 (此屬性值置於繫結的控制項屬性中)。The XPath query from container to the property value that is placed in the bound control property.

傳回

Object

Object,從資料繫結運算式的評估產生。An Object that results from the evaluation of the data-binding expression.

例外狀況

containerxpath 參數為 nullThe container or xpath parameter is null.

container 所指定的物件不是 IXPathNavigable 物件。The object specified by container is not an IXPathNavigable object.

範例

下列程式碼範例示範如何使用具有樣板 XmlDataSource 化控制項的控制項 Repeater 來顯示 XML 資料。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:

  • 顯示 XML 資料的 Web Form 頁面。A Web Forms page that displays XML data.

  • 包含資料的 XML 檔。An XML file that contains the data.

範例的第一個部分會顯示 Web Form 頁面,該頁面會顯示透過控制項存取的 XML 資料 XmlDataSourceThe first part of the example shows a Web Forms page that displays XML data accessed through an XmlDataSource control. Repeater控制項使用簡化的 Eval(Object, String) 方法語法,系結至所代表之 XML 檔中的資料項目 XmlDataSourceA Repeater control uses the simplified Eval(Object, String) method syntax to bind to data items within the XML document that the XmlDataSource represents. 它會使用 Select(Object, String) 方法來取出 IEnumerable 清單,並將其指派為控制項的晚期繫結 DataSource 屬性 RepeaterIt 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:XmlDataSource
        runat="server"
        id="XmlDataSource1"
        DataFile="bookstore2.xml"
        XPath="bookstore/genre[@name='fiction']" />

      <asp:Repeater
        runat="server"
        DataSourceID="XmlDataSource1">
        <ItemTemplate>
            <h1><%# XPath ("book/title") %></h1>
            <b>Author:</b>
            <%# XPath ("book/author/firstname") %>
            <%# XPath ("book/author/lastname") %>
            <asp:Repeater
                 DataSource='<%# XPathSelect ("book/chapters") %>'
                 runat="server">
                <ItemTemplate>
                     <%# XPath ("chapter/@name") %>
                </ItemTemplate>
            </asp:Repeater>
        </ItemTemplate>
    </asp:Repeater>
  </form>
  </body>
</html>
<%@ Page Language="VB" %>
<!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>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:XmlDataSource
        runat="server"
        id="XmlDataSource1"
        DataFile="bookstore2.xml"
        XPath="bookstore/genre[@name='fiction']" />

      <asp:Repeater
        runat="server"
        DataSourceID="XmlDataSource1">
        <ItemTemplate>
            <h1><%# XPath ("book/title") %></h1>
            <b>Author:</b>
            <%# XPath ("book/author/firstname") %>
            <%# XPath ("book/author/lastname") %>
            <asp:Repeater
                 DataSource='<%# XPathSelect ("book/chapters") %>'
                 runat="server">
                <ItemTemplate>
                     <%# XPath ("chapter/@name") %>
                </ItemTemplate>
            </asp:Repeater>
        </ItemTemplate>
    </asp:Repeater>
  </form>
  </body>
</html>

第二個範例會提供 XML 檔案(Bookstore2.xml),此檔案是用來做為上面所定義 Web Form 頁面中顯示的資料來源。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">  
        <author>  
          <firstname>test</firstname>  
          <lastname>test2</lastname>  
        </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>  

備註

Eval如果您想要簡化 XML 節點轉換成要在瀏覽器上顯示的文字字串,您可以用宣告方式來使用方法。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 on a browser. 若要這樣做,您必須將 <%# and %> 標記(也用於標準 ASP.NET 資料系結)放在資料系結運算式周圍。To do so, you must place the <%# and %> tags, which are also used in standard ASP.NET data binding, around the data-binding expression.

針對任何清單 ASP.NET 伺服器控制項(例如 DataListDataGridRepeater ), container 參數應該是 Container.DataItemFor any of the list ASP.NET server controls, such as DataList, DataGrid, or Repeater, the container parameter should be Container.DataItem. 如果您要針對頁面進行系結, container 參數應該是 PageIf you are binding against the page, the container parameter should be Page.

另請參閱

適用於

Eval(Object, String, String)

在執行階段評估 XPath 資料繫結運算式,並將結果格式化成為文字,以顯示於提出要求的瀏覽器中。Evaluates XPath data-binding expressions at run time and formats the result as text to be displayed in the requesting browser.

public:
 static System::String ^ Eval(System::Object ^ container, System::String ^ xPath, System::String ^ format);
public static string Eval (object container, string xPath, string format);
static member Eval : obj * string * string -> string
Public Shared Function Eval (container As Object, xPath As String, format As String) As String

參數

container
Object

運算式所據以評估的 IXPathNavigable 物件參考。The IXPathNavigable object reference that the expression is evaluated against. 這在網頁的指定語言中必須是有效的物件識別項。This must be a valid object identifier in the page's specified language.

xPath
String

container 到屬性值的 XPath 查詢 (此屬性值要置於繫結的控制項屬性中)。The XPath query from the container to the property value to be placed in the bound control property.

format
String

.NET Framework 格式字串 (類似於 Format(String, Object) 所使用的字串),會將 IXPathNavigable 物件 (由資料繫結運算式評估所產生) 轉換為可以由要求之瀏覽器所顯示的 StringA .NET Framework format string, similar to those used by Format(String, Object), that converts the IXPathNavigable object (which results from the evaluation of the data-binding expression) to a String that can be displayed by the requesting browser.

傳回

String

String,從資料繫結運算式評估和字串型別轉換產生。A String that results from the evaluation of the data-binding expression and conversion to a string type.

例外狀況

containerxpath 參數為 nullThe container or xpath parameter is null.

container 所指定的物件不是 IXPathNavigableThe object specified by container is not an IXPathNavigable.

備註

若要深入瞭解 .NET Framework 中的格式字串,請參閱 格式化類型To learn more about format strings in the .NET Framework, see Formatting Types.

Eval(Object, String)如果您想要簡化 XML 節點轉換成要在瀏覽器中顯示的文字字串,您可以用宣告的方式來使用方法。You can use the Eval(Object, String) method declaratively if you want to simplify the casting of an XML node to a text string to be displayed in a browser. 若要這樣做,您必須將 <%# and %> 標記(也用於標準 ASP.NET 資料系結)放在資料系結運算式周圍。To do so, you must place the <%# and %> tags, which are also used in standard ASP.NET data binding, around the data-binding expression.

針對任何清單 ASP.NET 伺服器控制項(例如 DataListDataGridRepeater ), container 參數應該是 Container.DataItemFor any of the list ASP.NET server controls, such as DataList, DataGrid, or Repeater, the container parameter should be Container.DataItem. 如果您要針對頁面進行系結, container 參數應該是 PageIf you are binding against the page, the container parameter should be Page.

適用於

Eval(Object, String, IXmlNamespaceResolver)

透過使用 IXmlNamespaceResolver 物件 (指定用於解析 XPath 運算式中的命名空間前置詞),在執行階段評估 XPath 資料繫結運算式,並將結果格式化成為文字,以顯示於要求的瀏覽器中。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.

public:
 static System::Object ^ Eval(System::Object ^ container, System::String ^ xPath, System::Xml::IXmlNamespaceResolver ^ resolver);
public static object Eval (object container, string xPath, System.Xml.IXmlNamespaceResolver resolver);
static member Eval : obj * string * System.Xml.IXmlNamespaceResolver -> obj
Public Shared Function Eval (container As Object, xPath As String, resolver As IXmlNamespaceResolver) As Object

參數

container
Object

運算式所據以評估的 IXPathNavigable 物件參考。The IXPathNavigable object reference that the expression is evaluated against. 這在網頁的指定語言中必須是有效的物件識別項。This must be a valid object identifier in the page's specified language.

xPath
String

container 到屬性值的 XPath 查詢 (此屬性值要置於繫結的控制項屬性中)。The XPath query from the container to the property value to be placed in the bound control property.

resolver
IXmlNamespaceResolver

IXmlNamespaceResolver 物件,用來解析 XPath 運算式中的命名空間前置詞。The IXmlNamespaceResolver object used to resolve namespace prefixes in the XPath expression.

傳回

Object

Object,從資料繫結運算式的評估產生。A Object that results from the evaluation of the data-binding expression.

備註

Eval如果您想要簡化 XML 節點轉換成要在瀏覽器中顯示的文字字串,您可以用宣告的方式來使用方法。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. 若要這樣做,您必須將 <%# and %> 標記(也用於標準 ASP.NET 資料系結)放在資料系結運算式周圍。To do so, you must place the <%# and %> tags, which are also used in standard ASP.NET data binding, around the data-binding expression. 資料系結運算式包含 XPath 運算式以及用 IXmlNamespaceResolver 來解析命名空間參考的物件。The data-binding expression includes the XPath expression and an IXmlNamespaceResolver object to resolve the namespace reference.

針對任何清單 ASP.NET 伺服器控制項(例如 DataListDataGridRepeater ), container 參數應該是 Container.DataItemFor any of the list ASP.NET server controls, such as DataList, DataGrid, or Repeater, the container parameter should be Container.DataItem. 如果您要針對頁面進行系結, container 參數應該是 PageIf you are binding against the page, the container parameter should be Page.

適用於

Eval(Object, String, String, IXmlNamespaceResolver)

透過使用 IXmlNamespaceResolver 物件 (指定用於解析 XPath 運算式中的命名空間前置詞),在執行階段評估 XPath 資料繫結運算式,並將結果格式化成為文字,以顯示於要求的瀏覽器中。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.

public:
 static System::String ^ Eval(System::Object ^ container, System::String ^ xPath, System::String ^ format, System::Xml::IXmlNamespaceResolver ^ resolver);
public static string Eval (object container, string xPath, string format, System.Xml.IXmlNamespaceResolver resolver);
static member Eval : obj * string * string * System.Xml.IXmlNamespaceResolver -> string
Public Shared Function Eval (container As Object, xPath As String, format As String, resolver As IXmlNamespaceResolver) As String

參數

container
Object

運算式所據以評估的 IXPathNavigable 物件參考。The IXPathNavigable object reference that the expression is evaluated against. 這在網頁的指定語言中必須是有效的物件識別項。This must be a valid object identifier in the page's specified language.

xPath
String

container 到屬性值的 XPath 查詢 (此屬性值要置於繫結的控制項屬性中)。The XPath query from the container to the property value to be placed in the bound control property.

format
String

.NET Framework 格式字串 (類似於 Format(String, Object) 所使用的字串),會將 IXPathNavigable 物件 (由資料繫結運算式評估所產生) 轉換為可以由要求之瀏覽器所顯示的 StringA .NET Framework format string, similar to those used by Format(String, Object), that converts the IXPathNavigable object (which results from the evaluation of the data-binding expression) to a String that can be displayed by the requesting browser.

resolver
IXmlNamespaceResolver

IXmlNamespaceResolver 物件,用來解析 XPath 運算式中的命名空間前置詞。The IXmlNamespaceResolver object used to resolve namespace prefixes in the XPath expression.

傳回

String

String,從資料繫結運算式評估和字串型別轉換產生。A String that results from the evaluation of the data-binding expression and conversion to a string type.

備註

Eval如果您想要簡化 XML 節點轉換成要在瀏覽器中顯示的文字字串,您可以用宣告的方式來使用方法。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. 若要這樣做,您必須將 <%# and %> 標記(也用於標準 ASP.NET 資料系結)放在資料系結運算式周圍。To do so, you must place the <%# and %> tags, which are also used in standard ASP.NET data binding, around the data-binding expression. 資料系結運算式包含 XPath 運算式以及用 IXmlNamespaceResolver 來解析命名空間參考的物件。The data-binding expression includes the XPath expression and an IXmlNamespaceResolver object to resolve the namespace reference.

針對任何清單 ASP.NET 伺服器控制項(例如 DataListDataGridRepeater ), container 參數應該是 Container.DataItemFor any of the list ASP.NET server controls, such as DataList, DataGrid, or Repeater, the container parameter should be Container.DataItem. 如果您要針對頁面進行系結, container 參數應該是 PageIf you are binding against the page, the container parameter should be Page.

適用於