XmlDataSource.Data 屬性

定義

取得或設定資料來源控制項繫結至的 XML 資料區塊。Gets or sets a block of XML data that the data source control binds to.

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

屬性值

String

XmlDataSource 控制項繫結至的內嵌 XML 資料字串。A string of inline XML data that the XmlDataSource control binds to. 預設值是 EmptyThe default value is Empty.

屬性

例外狀況

此文件正在載入。The document is loading.

範例

下列程式碼範例示範如何使用控制項, XmlDataSource 以控制項顯示包含屬性的內嵌 XML 資料 Data TreeViewThe following code example demonstrates how to use an XmlDataSource control to display inline XML data contained by the Data property with a TreeView 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
        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 屬性會指定為物件的多行內部屬性 XmlDataSourceIn declarative scenarios, the Data property is specified as a multiline inner property of the XmlDataSource object. 內部屬性與 XML 資料相容,因為它可讓您以任何方式將 XML 資料格式化,並忽略字元填補問題(例如填補引號字元)。An inner property is compatible with XML data, because it enables you to format the XML data in any way and ignore character padding issues, such as padding quote characters.

如果同時 DataFile 設定和 Data 屬性,則會 DataFile 優先使用屬性,且會使用 xml 檔案中的資料,而不是屬性中指定的 xml 資料 DataIf both the DataFile and Data properties are set, the DataFile property takes precedence and the data in the XML file is used instead of the XML data specified in the Data property.

如果您變更屬性的值 DataDataSourceChanged 就會引發事件。If you change the value of the Data property, the DataSourceChanged event is raised. 如果快取已啟用,而您變更的值 Data ,則快取會失效。If caching is enabled and you change the value of Data, the cache is invalidated.

適用於

另請參閱