XmlDataSource.Data 属性

定义

获取或设置数据源控件绑定到的 XML 数据块。

public:
 virtual property System::String ^ Data { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter("System.ComponentModel.MultilineStringConverter,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public virtual string Data { get; set; }
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.ComponentModel.TypeConverter("System.ComponentModel.MultilineStringConverter,System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public virtual string Data { get; set; }
[<System.ComponentModel.TypeConverter("System.ComponentModel.MultilineStringConverter,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.Data : string with get, set
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.ComponentModel.TypeConverter("System.ComponentModel.MultilineStringConverter,System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")>]
member this.Data : string with get, set
Public Overridable Property Data As String

属性值

XmlDataSource 控件绑定到的内联 XML 数据字符串。 默认值是 Empty

属性

例外

正在加载文档。

示例

下面的代码示例演示如何使用 控件 XmlDataSource 通过 控件显示 属性包含 DataTreeView 内联 XML 数据。

<%@ 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
        id="XmlDataSource1"
        runat="server" >
        <data>
          <Books>
            <LanguageBooks>
              <Book Title="Pure JavaScript" Author="Wyke, Gilliam, and Ting"/>
              <Book Title="Effective C++ Second Edition" Author="Scott Meyers"/>
              <Book Title="Assembly Language Step-By-Step" Author="Jeff Duntemann"/>
              <Book Title="Oracle PL/SQL" Author="Steven Feuerstein"/>
            </LanguageBooks>
            <SecurityBooks>
              <Book Title="Counter Hack" Author="Ed Skoudis"/>
            </SecurityBooks>
          </Books>
        </data>
        </asp:xmldatasource>

      <!- TreeView uses hierachical data, so the
          XmlDataSource uses an XmlHierarchicalDataSourceView
          when a TreeView is bound to it. -->

      <asp:treeview
        id="TreeView1"
        runat="server"
        datasourceid="XmlDataSource1">
        <databindings>
          <asp:treenodebinding datamember="Book" textfield="Title"/>
        </databindings>
      </asp:treeview>

    </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
        id="XmlDataSource1"
        runat="server" >
        <data>
          <Books>
            <LanguageBooks>
              <Book Title="Pure JavaScript" Author="Wyke, Gilliam, and Ting"/>
              <Book Title="Effective C++ Second Edition" Author="Scott Meyers"/>
              <Book Title="Assembly Language Step-By-Step" Author="Jeff Duntemann"/>
              <Book Title="Oracle PL/SQL" Author="Steven Feuerstein"/>
            </LanguageBooks>
            <SecurityBooks>
              <Book Title="Counter Hack" Author="Ed Skoudis"/>
            </SecurityBooks>
          </Books>
        </data>
        </asp:xmldatasource>

      <!- TreeView uses hierachical data, so the
          XmlDataSource uses an XmlHierarchicalDataSourceView
          when a TreeView is bound to it. -->

      <asp:treeview
        id="TreeView1"
        runat="server"
        datasourceid="XmlDataSource1">
        <databindings>
          <asp:treenodebinding datamember="Book" textfield="Title"/>
        </databindings>
      </asp:treeview>

    </form>
  </body>
</html>

注解

在声明性方案中, Data 属性被指定为 对象的多行内部属性 XmlDataSource 。 内部属性与 XML 数据兼容,因为它使您能够以任何方式设置 XML 数据的格式,并忽略字符填充问题,例如填充引号字符。

如果同时 DataFile 设置了 和 Data 属性,则 DataFile 属性优先,并且使用 XML 文件中的数据而不是 属性中指定的 Data XML 数据。

如果更改 属性的值 Data ,则会 DataSourceChanged 引发 事件。 如果启用了缓存,并且更改 了 Data的值,则缓存将失效。

适用于

另请参阅