Skip to main content
A newer version of this page is available. .
Tab

ASPxDataView.ItemTemplate Property

Gets or sets a common template used for displaying the content of a ASPxDataView‘s data items.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll

NuGet Package: DevExpress.Web

Declaration

[DefaultValue(null)]
public virtual ITemplate ItemTemplate { get; set; }

Property Value

Type Default Description
ITemplate *null*

An object that supports the ITemplate interface.

Remarks

Use the ItemTemplate property to define a common content for a ASPxDataView‘s data items. The template created using this property replaces the content of each data item preserving its style settings (if specified).

To display item data, populate the template with data-bound controls and use data binding expressions to associate them with the corresponding data fields. Below is an example of a simple item template.

...
<ItemTemplate>
    <table>
        <tr>
            <td>
                <dx:ASPxLabel ID="lblName" runat="server" Text='<%# Eval("Name") %>' Font-Bold="true" />
            </td>
            <td>
                <dx:ASPxImage ID="imgPhoto" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' ShowLoadingImage="true" />
            </td>
        </tr>
        <tr>
            <td>
                <dx:ASPxLabel ID="lblDescription" runat="server" Text='<%# Eval("Description") %>' />
            </td>
        </tr>
    </table>
</ItemTemplate>
...

ASPxDataView DataBound ItemTemplate

Note

Once a template defined via the ItemTemplate property is created within a control, it is instantiated within a container object of the DataViewItemTemplateContainer type. This container object exposes a set of specific properties to which the template’s child controls can be bound.

Example

This example demonstrates how data displayed by the ASPxDataView control can be filtered on custom callbacks initiated by a call to the client PerfromCallback method.

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v8.3, Version=8.3.2.0, Culture=neutral, 
PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxDataView" TagPrefix="dxdv" %>  
<%@ Register Assembly="DevExpress.Web.v8.3" Namespace="DevExpress.Web.ASPxEditors"
    TagPrefix="dxe" %> 

<!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_Load(object sender, EventArgs e) {
         if(!IsPostBack) { // start value
             cbCountry.DataBind();
             cbCountry.Value = 254; // USA for example
         }
         PrepareFilter();
     }

     protected void PrepareFilter() {
         dvAccessDataSource.SelectParameters[0].DefaultValue = cbCountry.Value.ToString();
         dvCity.DataBind();
     }
</script>


<html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
     <title>Filtering data within the ASPxDataView using custom callbacks</title>
 </head>
 <body>
     <form id="form1" runat="server">
         <table cellpadding="0" cellspacing="0">
 ComboBox 
            <tr>
                <td align="right" style="white-space: nowrap;">
                    <table cellpadding="0" cellspacing="0"><tr>
                        <td valign="middle">
                            <dxe:ASPxLabel ID="lblFilter" runat="server" 
                              Text="Filter: " AssociatedControlID="cbCountry">
                            </dxe:ASPxLabel>
                        </td>
                        <td valign="middle">
                            <dxe:ASPxComboBox ID="cbCountry" runat="server" 
                              DataSourceID="cbAccessDataSource"
                                TextField="Country" ValueField="CountryId" 
                                 ValueType="System.Int32" EnableIncrementalFiltering="True">
                            <ClientSideEvents SelectedIndexChanged="function(s, e) {
    dvCity.PerformCallback();
}" />
                            </dxe:ASPxComboBox>
                        </td>
                    </tr></table>
                </td>
            </tr>
            <tr><td style="height: 5px;"></td></tr> DataView 
            <tr>
                <td>
                    <dxdv:ASPxDataView ID="dvCity" runat="server" 
                      DataSourceID="dvAccessDataSource" 
                      ClientInstanceName="dvCity" Width="580px" AllowPaging="False">
                        <ItemStyle Height="60px" Width="150px" />
                        <ItemTemplate>
                            <table cellpadding="0" cellspacing="0">
                                <tr>
                                    <th>CountryId:</th>
                                    <td rowspan="3"><div style="width: 5px;"></div></td>
                                    <td><asp:Label ID="CountryIdLabel" runat="server" 
                                           Text='<%# Eval("CountryId") %>'>
                                           </asp:Label></td>
                                </tr>
                                <tr>
                                    <th>CityId:</th>
                                    <td><asp:Label ID="CityIdLabel" runat="server" 
                                           Text='<%# Eval("CityId") %>'></asp:Label></td>
                                </tr>
                                <tr>
                                    <th>City:</th>
                                    <td><asp:Label ID="CityLabel" runat="server" 
                                            Text='<%# Eval("City") %>'>
                                            </asp:Label></td>
                                </tr>
                            </table>
                        </ItemTemplate>
                        <Border BorderColor="#A0A0A0" BorderStyle="Solid" BorderWidth="1px" />
                        <Paddings Padding="5px" />
                    </dxdv:ASPxDataView>
                </td>
            </tr>         </table>

        <asp:AccessDataSource ID="cbAccessDataSource" runat="server" 
            DataFile="~/App_Data/EditorsSampleDB.mdb"
            SelectCommand="SELECT * FROM [Countries]">
        </asp:AccessDataSource>
        <asp:AccessDataSource ID="dvAccessDataSource" runat="server" 
            DataFile="~/App_Data/EditorsSampleDB.mdb"
            SelectCommand="SELECT * FROM [Cities] WHERE ([CountryId] = ?)">
            <SelectParameters>
                <asp:Parameter DefaultValue="1" Name="CountryId" Type="Int32" />
            </SelectParameters>
        </asp:AccessDataSource>     </form>
 </body>
 </html>
See Also