Language preference:

Phase 4 / Free form layout using the BLDDataField controls

While Field Templates layout and manage each DataField, they cannot be added directly into your Web Form. They lack key pieces of information to work: the name of the DataField and which Entity its on. The BLDDataField control remedies that.

BLDDataField control is always added within the DataBound control to provide data from the Entity class to the content. It already knows the Entity class and Entity instance containing the data from the DataSource control. You only need to assign the DataField name to its DataField property.

You add a BLDDataField when you are laying out the HTML and need to include a Field Template. Its always used in ListView and FormView controls because they require you to lay out all of the HTML. BLDListView and BLDFormView controls also support them, when you switch from using Pattern Templates to laying out the HTML in their <ItemTemplate> nodes.

<des:BLDFormView id="BLDFormView1" runat="server" DataSourceID="DataSource1" ContainerNamedPart="Div" >
   <ItemTemplate>
      <des:BLDDataField id="ProductName" runat="Server" DataField="ProductName" />
      <br/>by 
      <des:BLDDataField id="SupplierHomePage" runat="server" DataField="Supplier.HomePage" />
      <br/>
      <des:BLDDataField id="UnitPrice" runat="server" DataField="UnitPrice" />
   </ItemTemplate>
</des:BLDFormView>

When using GridView or DetailsView, you will use the BLDField control which generates a BLDDataField.

When using Pattern Templates (described later), you will use the DataFieldInPattern object which also generates a BLDDataField.

Use the Source Code Browser to see examples of each DataBound control using these objects.

In the next topic, you will learn about the BLDLabel control.



Open the Source Code Browser (C# only)
Source Code Browser
 
<%Control Language="C#" AutoEventWireup="true" %>
<des:BLDPageManager ID="BLDPageManager1" runat="server" AutoLoadForeignKeys="true">
   <Adapters>
      <des:BLDFormViewAdapter DataBoundControlID="BLDFormView1" SupportsEditActions="false" SupportsInsertActions="false" />
   </Adapters>
</des:BLDPageManager>
<asp:UpdatePanel id="UpdatePanel1" runat="server">
   <ContentTemplate>
      <des:BLDFormView ID="BLDFormView1" runat="server" 
         DataSourceID="DataSource1" DataKeyNames="ProductID" AllowPaging="True"
         AutoGenerateButtons="None" ShowFooterRow="true" AutoScaffold="No" >
         <ItemTemplate>
            <table class="DetailsViewContainer">
               <tr class="DetailsViewDataFieldRow">
                  <td class="DetailsViewLabelContainer">
                     <des:BLDLabel ID="BLDLabel1" runat="server" AssociatedControlID="ProductNameLabel" />
                  </td>
                  <td class="DetailsViewDataContainer">
                     <des:BLDDataField ID="ProductNameLabel" runat="server" DataField="ProductName" />
                  </td>
               </tr>
               <tr class="DetailsViewDataFieldRow">
                  <td class="DetailsViewLabelContainer">
                     <des:BLDLabel ID="BLDLabel2" runat="server" AssociatedControlID="UnitPriceLabel" />
                  </td>
                  <td class="DetailsViewDataContainer">
                     <des:BLDDataField ID="UnitPriceLabel" runat="server" DataField="UnitPrice" />
                  </td>
               </tr>
               <tr class="DetailsViewDataFieldRow">
                  <td class="DetailsViewLabelContainer">
                     <des:BLDLabel ID="BLDLabel3" runat="server" AssociatedControlID="CategoryLabel" />
                  </td>
                  <td class="DetailsViewDataContainer">
                     <des:BLDDataField ID="CategoryLabel" runat="server" DataField="Category" />
                  </td>
               </tr>
               <des:BLDWidgetsView id="BLDWidgetsView1" runat="server" ContainerTag="TableRowWithOneCell" />
            </table>
         </ItemTemplate>
         <PagerSettings Visible="false" />
      </des:BLDFormView>
   </ContentTemplate>
</asp:UpdatePanel>
<des:EntityDAODataSource ID="DataSource1" runat="server" 
   EntityTypeName="PeterBlum.WithDataAnnotations.Product"
   EnableUpdate="false" EnableInsert="false" EnableDelete="false" >
</des:EntityDAODataSource>