This documentation is archived and is not being maintained.

DataList.ExtractTemplateRows Property

Gets or sets a value that indicates whether the rows of a Table control, defined in each template of a DataList control, are extracted and displayed.

[Visual Basic]
Public Overridable Property ExtractTemplateRows As Boolean
[C#]
public virtual bool ExtractTemplateRows {get; set;}
[C++]
public: __property virtual bool get_ExtractTemplateRows();
public: __property virtual void set_ExtractTemplateRows(bool);
[JScript]
public function get ExtractTemplateRows() : Boolean;
public function set ExtractTemplateRows(Boolean);

Property Value

true if the rows of a Table control, defined in each template of a DataList control, are extracted and displayed; otherwise, false. The default value is false.

Remarks

The contents of the DataList control are specified by using templates. Normally, you list controls that you want to display in the templates. You can also place a Table control in a template and display the rows of the table.

Use the ExtractTemplateRows property to specify whether the rows of a Table control defined in each template of a DataList control are extracted and displayed. All rows extracted from the templates of the DataList control are displayed in a single table. This allows you to create a single table from other smaller tables and still maintain the features of the DataList control.

Note   When this property is set to true, you must provide a well-formed Table control for each template you want to include in the DataList control. Only the rows of the tables will be displayed. All other content in the template will be ignored. You must use a Table control for this feature to work properly. The System.Web.UI.HtmlControls.HtmlTable control is not compatible with this property.

When you create a cell for a Table control in a template, you can use the ColumnSpan property of the TableCell object to control the number of columns the cell spans. You can also use the RowSpan property to control the number of rows the cell spans.

Note   The RepeatColumns, RepeatDirection, and RepeatLayout properties do not affect the appearance of the DataList control when this property is set to true.

Example

[Visual Basic, C#] The following example demonstrate how to use the ExtractTemplateRows property to extract and display the rows of Table controls defined in the templates of the DataList control.

[Visual Basic, C#] Note   The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see Web Forms Code Model.
[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<html>
   <script runat="server">
 
    Function CreateDataSource() As ICollection
        Dim dt As New DataTable()
        Dim dr As DataRow
        
        dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
        dt.Columns.Add(New DataColumn("PriceValue", GetType(String)))
        dt.Columns.Add(New DataColumn("DescriptionValue", GetType(String)))
        
        Dim i As Integer
        For i = 0 To 9
            dr = dt.NewRow()
            dr(0) = "Item " & i.ToString()
            dr(1) =(1.23 *(i + 1)).ToString()
            dr(2) = "Description for Item " + i.ToString()
            dt.Rows.Add(dr)
        Next i
        
        Dim dv As New DataView(dt)
        Return dv
    End Function 'CreateDataSource


    Sub Page_Load(sender As Object, e As EventArgs)
        If Not IsPostBack Then
            DataList1.DataSource = CreateDataSource()
            DataList1.DataBind()
        End If
    End Sub 'Page_Load
     
   </script>
 
<body>
 
   <form runat=server>

      <h3>DataList ExtractTemplateRows Example</h3>
 
      <asp:DataList id="DataList1" runat="server"
           BorderColor="black"
           CellPadding="3"
           Font-Name="Verdana"
           Font-Size="8pt"
           ExtractTemplateRows="true"
           GridLines="Both">

         <HeaderStyle BackColor="#aaaadd">
         </HeaderStyle>

         <AlternatingItemStyle BackColor="Gainsboro">
         </AlternatingItemStyle>

         <HeaderTemplate>

            <asp:Table id="Table1" runat="server">

                <asp:TableRow>

                   <asp:TableCell
                        ColumnSpan="2">
                      Items
                   </asp:TableCell>

                </asp:TableRow>

            </asp:Table>

         </HeaderTemplate>
               
         <ItemTemplate>

            <asp:Table id="Table2" runat="server">

                <asp:TableRow>

                   <asp:TableCell
                        Text='<%# DataBinder.Eval(Container.DataItem, "StringValue") %>'>
                   </asp:TableCell>

                   <asp:TableCell
                        Text='<%# DataBinder.Eval(Container.DataItem, "PriceValue") %>'>
                   </asp:TableCell>

                </asp:TableRow>

                <asp:TableRow>

                   <asp:TableCell
                        ColumnSpan="2"
                        Text='<%# DataBinder.Eval(Container.DataItem, "DescriptionValue") %>'>
                   </asp:TableCell>

                </asp:TableRow>

            </asp:Table>

         </ItemTemplate>
 
      </asp:DataList>
 
   </form>
 
</body>
</html>


[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
 
<html>
   <script runat="server">
 
      ICollection CreateDataSource() 
      {
         DataTable dt = new DataTable();
         DataRow dr;
 
         dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
         dt.Columns.Add(new DataColumn("PriceValue", typeof(string)));
         dt.Columns.Add(new DataColumn("DescriptionValue", typeof(string)));
  
         for (int i = 0; i < 10; i++) 
         {
            dr = dt.NewRow();
            dr[0] = "Item " + i.ToString();
            dr[1] = (1.23 * (i+1)).ToString();
            dr[2] = "Description for Item " + i.ToString();
            dt.Rows.Add(dr);
         }
 
         DataView dv = new DataView(dt);
         return dv;
      }
 
      void Page_Load(Object sender, EventArgs e) 
      {
         if (!IsPostBack) 
         {
            DataList1.DataSource = CreateDataSource();
            DataList1.DataBind();
         }
      }
 
   </script>
 
<body>
 
   <form runat=server>

      <h3>DataList ExtractTemplateRows Example</h3>
 
      <asp:DataList id="DataList1" runat="server"
           BorderColor="black"
           CellPadding="3"
           Font-Name="Verdana"
           Font-Size="8pt"
           ExtractTemplateRows="true"
           GridLines="Both">

         <HeaderStyle BackColor="#aaaadd">
         </HeaderStyle>

         <AlternatingItemStyle BackColor="Gainsboro">
         </AlternatingItemStyle>

         <HeaderTemplate>

            <asp:Table id="Table1" runat="server">

                <asp:TableRow>

                   <asp:TableCell
                        ColumnSpan="2">
                      Items
                   </asp:TableCell>

                </asp:TableRow>

            </asp:Table>

         </HeaderTemplate>
               
         <ItemTemplate>

            <asp:Table id="Table2" runat="server">

                <asp:TableRow>

                   <asp:TableCell
                        Text='<%# DataBinder.Eval(Container.DataItem, "StringValue") %>'>
                   </asp:TableCell>

                   <asp:TableCell
                        Text='<%# DataBinder.Eval(Container.DataItem, "PriceValue") %>'>
                   </asp:TableCell>

                </asp:TableRow>

                <asp:TableRow>

                   <asp:TableCell
                        ColumnSpan="2"
                        Text='<%# DataBinder.Eval(Container.DataItem, "DescriptionValue") %>'>
                   </asp:TableCell>

                </asp:TableRow>

            </asp:Table>

         </ItemTemplate>
 
      </asp:DataList>
 
   </form>
 
</body>
</html>

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

DataList Class | DataList Members | System.Web.UI.WebControls Namespace | Table | TableRow | TableCell | AlternatingItemTemplate | EditItemTemplate | FooterTemplate | HeaderTemplate | ItemTemplate | SelectedItemTemplate | SeparatorTemplate

Show: