Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DynamicControl.DataField Property

Gets or sets the name of the data field that the DynamicControl control is bound to.

Namespace:  System.Web.DynamicData
Assembly:  System.Web.DynamicData (in System.Web.DynamicData.dll)

public string DataField { get; set; }
<asp:DynamicControl DataField="String" />

Property Value

Type: System.String
The name of the data field to bind the DynamicControl control to. The default is an empty string (""), which indicates that this property is not set.

Use the DataField property to specify the data field to bind to the DynamicControl control. The data field can be the column name or, for foreign key columns, the relationship name.

By default, the specified data field is displayed by the DynamicControl control using the field template that is associated with the field data type. You can change the field template that is rendered for the data field by setting the UIHint property. You can also format the displayed text by setting the DataFormatString property.

NoteNote:

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. For more information, see ASP.NET Dynamic Data Model Overview.

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>

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1

Community Additions

ADD
Show:
© 2015 Microsoft