Share via


DynamicControl.DataField Proprietà

Definizione

Ottiene o imposta il nome del campo dati a cui è associato il controllo DynamicControl.

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

Valore della proprietà

Nome del campo dati da associare al controllo DynamicControl. Il valore predefinito è una stringa vuota (""), a indicare che questa proprietà non è impostata.

Esempio

Nell'esempio seguente viene illustrato come utilizzare la DataField proprietà per specificare il campo da visualizzare in un DynamicControl controllo .

<%@ Page Language="C#" %>

<%@ Register Assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Web.UI.WebControls" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  protected void Page_Init(object sender, EventArgs e)
  {
      DynamicDataManager1.RegisterControl(ProductsFormView);
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>DynamicControl.DataField Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
        AutoLoadForeignKeys="true" />
        
      <asp:FormView ID="ProductsFormView" runat="server" DataSourceID="ProductsDataSource" 
        DataKeyNames="ProductID" AllowPaging="True" 
        PagerSettings-PageButtonCount="15">
        <ItemTemplate>
          Name:
          <asp:DynamicControl runat="server" DataField="Name" />
          <br />
          Product Number:
          <asp:DynamicControl runat="server" DataField="ProductNumber" />
          <br />
          Product Category:
          <asp:DynamicControl runat="server" DataField="ProductCategory" />
          <br />
        </ItemTemplate>
      </asp:FormView>
      
      <!-- This example uses Microsoft SQL Server and connects   -->
      <!-- to the AdventureWorksLT sample database.              -->      
      <asp:EntityDataSource ID="ProductsDataSource" runat="server"
        ContextTypeName="AdventureWorksLT_DataModel.AdventureWorksLT_DataEntities"
        EntitySetName="Product"
        Where='it.Size="L"'>
      </asp:EntityDataSource>
      
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<%@ Register Assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Web.UI.WebControls" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
        DynamicDataManager1.RegisterControl(ProductsFormView)
    End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title>DynamicControl.DataField Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:DynamicDataManager ID="DynamicDataManager1" runat="server"
        AutoLoadForeignKeys="true" />
        
      <asp:FormView ID="ProductsFormView" runat="server" DataSourceID="ProductsDataSource" 
        DataKeyNames="ProductID" AllowPaging="True" 
        PagerSettings-PageButtonCount="15">
        <ItemTemplate>
          Name:
          <asp:DynamicControl runat="server" DataField="Name" />
          <br />
          Product Number:
          <asp:DynamicControl runat="server" DataField="ProductNumber" />
          <br />
          Product Category:
          <asp:DynamicControl runat="server" DataField="ProductCategory" />
          <br />
        </ItemTemplate>
      </asp:FormView>

      <!-- This example uses Microsoft SQL Server and connects   -->
      <!-- to the AdventureWorksLT sample database.              -->
      <asp:EntityDataSource ID="ProductsDataSource" runat="server"
        ContextTypeName="AdventureWorksLT_DataModel.AdventureWorksLT_DataEntities"
        EntitySetName="Product"
        Where='it.Size="L"'>
      </asp:EntityDataSource>
      
    </div>
    </form>
</body>
</html>

Commenti

Utilizzare la DataField proprietà per specificare il campo dati da associare al DynamicControl controllo . Il campo dati può essere il nome della colonna o, per le colonne chiave esterna, il nome della relazione.

Per impostazione predefinita, il DynamicControl campo dati specificato viene visualizzato dal controllo utilizzando il modello di campo associato al tipo di dati del campo. È possibile modificare il modello di campo di cui viene eseguito il rendering per il campo dati impostando la UIHint proprietà . È anche possibile formattare il testo visualizzato impostando la DataFormatString proprietà .

Nota Se si desidera modificare la visualizzazione e il comportamento di un campo dati a livello globale, è necessario applicare attributi al modello di dati anziché impostarlo in una particolare istanza del DynamicControl controllo. Per altre informazioni, vedere ASP.NET Dynamic Data.

Si applica a

Vedi anche