XmlDataSource.DataFile XmlDataSource.DataFile XmlDataSource.DataFile XmlDataSource.DataFile Property

Definizione

Specifica il nome file di un file XML a cui si associa il controllo origine dati.Specifies the file name of an XML file that the data source binds to.

public:
 virtual property System::String ^ DataFile { System::String ^ get(); void set(System::String ^ value); };
public virtual string DataFile { get; set; }
member this.DataFile : string with get, set
Public Overridable Property DataFile As String

Valore della proprietà

Percorso fisico assoluto o relativo del file XML contenente i dati rappresentati dal controllo XmlDataSource.The absolute physical path or relative path of the XML file that contains data that the XmlDataSource control represents. Il valore predefinito è Empty.The default value is Empty.

Eccezioni

È in corso il caricamento del documento.The document is loading.

Esempi

Esempio di codice seguente viene illustrato come utilizzare un XmlDataSource controllo per visualizzare i dati XML contenuti in un file con un TreeView controllo.The following code example demonstrates how to use an XmlDataSource control to display XML data contained in a file 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"
        datafile="books.xml" />

      <!- 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"
        datafile="books.xml" />

      <!- 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>

Il file XML nell'esempio di codice presenta i seguenti dati:The XML file in the code example has the following data:

<books>  
   <computerbooks>  
     <book title="Secrets of Silicon Valley" author="Sheryl Hunter"/>  
     <book title="Straight Talk About Computers" author="Dean Straight"/>  
     <book title="You Can Combat Computer Stress!" author="Marjorie Green"/>                  
   </computerbooks>  
   <cookbooks>  
     <book title="Silicon Valley Gastronomic Treats" author="Innes del Castill"/>  
   </cookbooks>  
</books>  

Commenti

Se entrambi i DataFile e Data sono impostate, il DataFile proprietà ha la precedenza e i dati nel file XML viene usati invece i dati XML specificati nel Data proprietà.If 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.

Se si modifica il valore della DataFile proprietà, il DataSourceChanged viene generato l'evento.If you change the value of the DataFile property, the DataSourceChanged event is raised. Se la memorizzazione nella cache è abilitata e si modifica il valore di DataFile, la cache viene invalidata.If caching is enabled and you change the value of DataFile, the cache is invalidated.

Si applica a

Vedi anche