DynamicControl.DataField Propriedade

Definição

Obtém ou define o nome do campo de dados ao qual o controle DynamicControl está associado.Gets or sets the name of the data field that the DynamicControl control is bound to.

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

Valor da propriedade

String

O nome do campo de dados ao qual associar o DynamicControl controle.The name of the data field to bind the DynamicControl control to. O padrão é uma cadeia de caracteres vazia (""), que indica que essa propriedade não está definida.The default is an empty string (""), which indicates that this property is not set.

Exemplos

O exemplo a seguir demonstra como usar a DataField propriedade para especificar qual campo exibir em um DynamicControl controle.The following example demonstrates how to use the DataField property to specify which field to display in a DynamicControl control.

<%@ 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>

Comentários

Use a DataField propriedade para especificar o campo de dados a ser associado ao DynamicControl controle.Use the DataField property to specify the data field to bind to the DynamicControl control. O campo de dados pode ser o nome da coluna ou, para colunas de chave estrangeira, o nome da relação.The data field can be the column name or, for foreign key columns, the relationship name.

Por padrão, o campo de dados especificado é exibido pelo DynamicControl controle usando o modelo de campo que está associado ao tipo de dados de campo.By default, the specified data field is displayed by the DynamicControl control using the field template that is associated with the field data type. Você pode alterar o modelo de campo que é renderizado para o campo de dados definindo a UIHint propriedade.You can change the field template that is rendered for the data field by setting the UIHint property. Você também pode formatar o texto exibido definindo a DataFormatString propriedade.You can also format the displayed text by setting the DataFormatString property.

Observação Se você quiser alterar a exibição e o comportamento de um campo de dados globalmente, deverá aplicar atributos ao seu modelo de dados em vez de defini-los em uma determinada instância do DynamicControl controle.Note If you want to change the display and behavior of a data field globally, you must apply attributes to your data model instead of setting this in a particular instance of the DynamicControl control. Para obter mais informações, consulte ASP.NET dados dinâmicos.For more information, see ASP.NET Dynamic Data.

Aplica-se a

Confira também