Language preference:

Phase 4 / Using Pattern Templates

We've just learned how to create a Pattern Template. Now we'll learn how to use it in your Web Form.

The primary tool is the DataFieldInPattern object - You specify a DataField name in its DataField property. It copies that DataField name into the BLDDataField control's DataField property within the Pattern Template.

The DataFieldInPattern object does not specify the Pattern Template file. It must be used inside one of these controls which do specify the Pattern Template file in their PatternTemplateName properties.

  • The BLDPatternForDataField control replaces the HTML for a single DataField within the <ItemTemplate>, <EditItemTemplate>, and <InsertItemTemplate> nodes of these DataBound controls: BLDListView, BLDFormView, ListView, and FormView.

    The Pattern Template files it supports can only contain one BLDDataField, which gets its DataField property assigned automatically from the DataField property on BLDPatternForDataField control. In fact, it doesn't appear to use the DataFieldInPattern object because you set the DataField property in the control itself. Yet internally it is using the DataFieldInPattern object.

    <ItemTemplate>
      <des:BLDPatternForDataField id="ProductNameData" runat="server"
        PatternTemplateName="One Field TableRow" DataField="ProductName" />
      <des:BLDPatternForDataField id="DescriptionData" runat="server"
        PatternTemplateName="One Field TableRow" DataField="Description" />
      <des:BLDPatternForDataField id="UnitPriceData" runat="server"
        PatternTemplateName="One Field TableRow" DataField="UnitPrice" />
    </ItemTemplate>
  • The BLDPatternForDataFields control (notice the 's' at the end of the name) replaces the HTML for multiple DataFields within the <ItemTemplate>, <EditItemTemplate>, and <InsertItemTemplate> nodes of these DataBound controls: BLDListView, BLDFormView, ListView, and FormView.

    Add DataFieldInPattern objects to its ItemsInPattern collection in the order they should appear in the Web Form.

    The Pattern Template files it supports should have a BLDDataField control for each DataFieldInPattern object that you specify, or it must be a Parts Pattern Template. The Parts Pattern Template will insert the content for a "DataCell" with each DataFieldInPattern object supplied.

    <ItemTemplate>
      <des:BLDPatternForDataFields id="Pattern1" runat="server"
        PatternTemplateName="Three Field TableRow" >
        <ItemsInPattern>
          <des:DataFieldInPattern DataField="ProductName" />
          <des:DataFieldInPattern DataField="Description" />
          <des:DataFieldInPattern DataField="UnitPrice" />
        </ItemsInPattern>
      </des:BLDPatternForDataFields>
    </ItemTemplate>
  • The BLDListView and BLDFormView controls are usually setup by adding DataFieldInPattern objects to their ItemsInPattern collections. (By leaving ItemsInPattern empty, you get Automatic Scaffolding.)

    BLDListView and BLDFormView only support Parts Pattern Templates in their PatternTemplateName properties because they generate all of the HTML related to the data, including its outer frame, headers, footers, and much more. These "parts" are layed out within the Parts Pattern Template file. In fact, each "part" can have several alternatives, each given a name. As a result, they are called "Named Parts". If you want to select an alternative "DataCell" part, do it on the DataFieldInPattern object by specifying the name in its NamedPart property.

    Within the BLDListView, Headers and Footers are also generated from the DataFieldInPattern objects. Headers need column titles and that comes from the DataField associated with the column drawn. Footers can show a column total, which again comes from the DataField.

    <des:BLDFormView id="BLDFormView1" runat="server" DataSourceID="DataSource1" >
       <ItemsInPattern>
          <des:DataFieldInPattern DataField="ProductName" NamedPart="TitleFormat" />
          <des:DataFieldInPattern DataField="Supplier.HomePage" Label-Text="Vendor" />
          <des:DataFieldInPattern DataField="UnitPrice" />
       </ItemsInPattern>
    </des:BLDFormView>

    DataFieldInPattern objects can also specify text used for field labels, header titles, and footer text. When the Pattern Template has a BLDLabel control, it will be assigned the Display Name of the DataField to which its assigned. To change it, set the new text in the Label-Text property. The Header title also gets text from the Display Name. To change it, set the new text in the HeaderText property. The Footer gets its text from the FooterText property.

In the next topic, you will learn about how to change the default styles within Pattern Template from your Web Forms.