XPathBinder.Eval 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在运行时针对 IXPathNavigable 对象分析和计算 XPath 数据绑定表达式。
重载
| 名称 | 说明 |
|---|---|
| Eval(Object, String) |
在运行时计算 XPath 数据绑定表达式。 |
| Eval(Object, String, String) |
在运行时计算 XPath 数据绑定表达式,并将结果格式化为在请求浏览器中显示的文本。 |
| Eval(Object, String, IXmlNamespaceResolver) |
在运行时计算 XPath 数据绑定表达式,并使用指定的对象解析 XPath 表达式中的命名空间前缀,将结果格式化为在请求浏览器中 IXmlNamespaceResolver 显示的文本。 |
| Eval(Object, String, String, IXmlNamespaceResolver) |
在运行时计算 XPath 数据绑定表达式,并使用指定的对象解析 XPath 表达式中的命名空间前缀,将结果格式化为在请求浏览器中 IXmlNamespaceResolver 显示的文本。 |
Eval(Object, String)
在运行时计算 XPath 数据绑定表达式。
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计算表达式的对象引用。 这必须是页面指定语言中的有效对象标识符。
- xPath
- String
从 XPath 查询 container 到放置在绑定控件属性中的属性值。
返回
由数据绑定表达式计算得出的一个 Object 结果。
例外
container或xpath参数为 null.
指定的 container 对象不是对象 IXPathNavigable 。
示例
下面的代码示例演示如何将 XmlDataSource 控件与模板化 Repeater 控件一起使用以显示 XML 数据。 此示例有两个部分:
显示 XML 数据的 Web 窗体页。
包含数据的 XML 文件。
该示例的第一部分显示一个 Web 窗体页,该页显示通过控件访问的 XmlDataSource XML 数据。 Repeater控件使用简化Eval(Object, String)的方法语法绑定到表示的 XmlDataSource XML 文档中的数据项。 它使用 Select(Object, String) 该方法检索 IEnumerable 列表并将其指定为控件的后期绑定 DataSource 属性 Repeater 。
<%@ 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 窗体页中显示的数据的源。
<?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>
注解
如果要简化 XML 节点转换为要在浏览器中显示的文本字符串,则可以以声明方式使用 Eval 该方法。 为此,必须将%# 和 %> 标记放在<数据绑定表达式周围,这些标记也用于标准 ASP.NET 数据绑定。
对于任何列表 ASP.NET 服务器控件(例如DataList,DataGrid或Repeatercontainer)参数应为 Container.DataItem。 如果要对页面进行绑定,则 container 参数应为 Page。
另请参阅
适用于
Eval(Object, String, String)
在运行时计算 XPath 数据绑定表达式,并将结果格式化为在请求浏览器中显示的文本。
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计算表达式的对象引用。 这必须是页面指定语言中的有效对象标识符。
- xPath
- String
要 container 放置在绑定控件属性中的属性值的 XPath 查询。
- format
- String
.NET Framework 格式字符串,类似于用于Format(String, Object)将对象(从数据绑定表达式的计算结果)转换为IXPathNavigableString可由请求浏览器显示的字符串。
返回
由 String 数据绑定表达式的计算和转换为字符串类型的结果。
例外
container或xpath参数为 null.
指定的 container 对象不是 IXPathNavigable.
注解
若要详细了解 .NET Framework 中的格式字符串,请参阅 “格式设置类型”。
如果要简化 XML 节点转换为要在浏览器中显示的文本字符串,则可以以声明方式使用 Eval(Object, String) 该方法。 为此,必须将%# 和 %> 标记放在<数据绑定表达式周围,这些标记也用于标准 ASP.NET 数据绑定。
对于任何列表 ASP.NET 服务器控件(例如DataList,DataGrid或Repeatercontainer)参数应为 Container.DataItem。 如果要对页面进行绑定,则 container 参数应为 Page。
另请参阅
适用于
Eval(Object, String, IXmlNamespaceResolver)
在运行时计算 XPath 数据绑定表达式,并使用指定的对象解析 XPath 表达式中的命名空间前缀,将结果格式化为在请求浏览器中 IXmlNamespaceResolver 显示的文本。
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计算表达式的对象引用。 这必须是页面指定语言中的有效对象标识符。
- xPath
- String
要 container 放置在绑定控件属性中的属性值的 XPath 查询。
- resolver
- IXmlNamespaceResolver
IXmlNamespaceResolver用于解析 XPath 表达式中的命名空间前缀的对象。
返回
一个 Object 由数据绑定表达式计算的结果。
注解
如果要简化 XML 节点转换为要在浏览器中显示的文本字符串,则可以以声明方式使用 Eval 该方法。 为此,必须将%# 和 %> 标记放在<数据绑定表达式周围,这些标记也用于标准 ASP.NET 数据绑定。 数据绑定表达式包括 XPath 表达式和 IXmlNamespaceResolver 用于解析命名空间引用的对象。
对于任何列表 ASP.NET 服务器控件(例如DataList,DataGrid或Repeatercontainer)参数应为 Container.DataItem。 如果要对页面进行绑定,则 container 参数应为 Page。
适用于
Eval(Object, String, String, IXmlNamespaceResolver)
在运行时计算 XPath 数据绑定表达式,并使用指定的对象解析 XPath 表达式中的命名空间前缀,将结果格式化为在请求浏览器中 IXmlNamespaceResolver 显示的文本。
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计算表达式的对象引用。 这必须是页面指定语言中的有效对象标识符。
- xPath
- String
要 container 放置在绑定控件属性中的属性值的 XPath 查询。
- format
- String
.NET Framework 格式字符串,类似于用于Format(String, Object)将对象(从数据绑定表达式的计算结果)转换为IXPathNavigableString可由请求浏览器显示的字符串。
- resolver
- IXmlNamespaceResolver
IXmlNamespaceResolver用于解析 XPath 表达式中的命名空间前缀的对象。
返回
由 String 数据绑定表达式的计算和转换为字符串类型的结果。
注解
如果要简化 XML 节点转换为要在浏览器中显示的文本字符串,则可以以声明方式使用 Eval 该方法。 为此,必须将%# 和 %> 标记放在<数据绑定表达式周围,这些标记也用于标准 ASP.NET 数据绑定。 数据绑定表达式包括 XPath 表达式和 IXmlNamespaceResolver 用于解析命名空间引用的对象。
对于任何列表 ASP.NET 服务器控件(例如DataList,DataGrid或Repeatercontainer)参数应为 Container.DataItem。 如果要对页面进行绑定,则 container 参数应为 Page。