How to: Show a Complex Property Value in DataItemTemplate of a Column
- 4 minutes to read
This example demonstrates how to show a complex property value in DataItemTemplate of a column using BindingExpressions
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-show-a-complex-property-value-in-dataitemtemplate-of-a-column-t274100
- Default.aspx.cs
- Default.aspx (C#)
- ComplexPropertyInTemplate.cs
- ComplexPropertyInTemplate.vb
- Default.aspx.vb
- Default.aspx (VB.NET)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:aspxcardview ID="ASPxCardView1" AutoGenerateColumns="False" EnableCardsCache="False" runat="server" DataSourceID="ObjectDataSource1" KeyFieldName="Id">
<SettingsBehavior AllowFocusedCard="True" />
<Columns>
<dx:CardViewTextColumn FieldName="Id" VisibleIndex="0" Width="10%">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="Name" VisibleIndex="1" Width="30%">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn Caption="Street" FieldName="Address" VisibleIndex="2" Width="30%">
<DataItemTemplate>
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Text='<%# Eval("Address.Street") %>' Width="100%"></dx:ASPxTextBox>
</DataItemTemplate>
</dx:CardViewTextColumn>
<dx:CardViewTextColumn Caption="City" FieldName="Address" VisibleIndex="3" Width="33%">
<DataItemTemplate>
<dx:ASPxTextBox ID="ASPxTextBox2" runat="server" Text='<%# Eval("Address.City") %>' Width="100%"></dx:ASPxTextBox>
</DataItemTemplate>
</dx:CardViewTextColumn>
</Columns>
</dx:aspxcardview>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="SelectData" TypeName="Person">
</asp:ObjectDataSource>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
public class Person {
private int id;
private string name;
private Address address;
public Person() {
}
public Person(int id, string name, Address address) {
this.id = id;
this.name = name;
this.address = address;
}
public int Id { get{ return id; } }
public string Name { get{ return name; } }
public Address Address { get{ return address; } }
public List<Person> SelectData() {
List<Person> persons = new List<Person>();
persons.Add(new Person(0, "John", new Address("Home Lane", "Homesville")));
persons.Add(new Person(1, "Henry", new Address("436 1st Ave", "Cleveland")));
return persons;
}
}
public class Address {
string street;
string city;
public Address(string street, string city) {
this.street = street;
this.city = city;
}
public string Street { get { return street; } }
public string City { get { return city; } }}
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Collections.Generic
Public Class Person
Private id_Renamed As Integer
Private name_Renamed As String
Private address_Renamed As Address
Public Sub New()
End Sub
Public Sub New(ByVal id As Integer, ByVal name As String, ByVal address As Address)
Me.id_Renamed = id
Me.name_Renamed = name
Me.address_Renamed = address
End Sub
Public ReadOnly Property Id() As Integer
Get
Return id_Renamed
End Get
End Property
Public ReadOnly Property Name() As String
Get
Return name_Renamed
End Get
End Property
Public ReadOnly Property Address() As Address
Get
Return address_Renamed
End Get
End Property
Public Function SelectData() As List(Of Person)
Dim persons As New List(Of Person)()
persons.Add(New Person(0, "John", New Address("Home Lane", "Homesville")))
persons.Add(New Person(1, "Henry", New Address("436 1st Ave", "Cleveland")))
Return persons
End Function
End Class
Public Class Address
Private street_Renamed As String
Private city_Renamed As String
Public Sub New(ByVal street As String, ByVal city As String)
Me.street_Renamed = street
Me.city_Renamed = city
End Sub
Public ReadOnly Property Street() As String
Get
Return street_Renamed
End Get
End Property
Public ReadOnly Property City() As String
Get
Return city_Renamed
End Get
End Property
End Class
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
End Class
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:aspxcardview ID="ASPxCardView1" AutoGenerateColumns="False" EnableCardsCache="False" runat="server" DataSourceID="ObjectDataSource1" KeyFieldName="Id">
<SettingsBehavior AllowFocusedCard="True" />
<Columns>
<dx:CardViewTextColumn FieldName="Id" VisibleIndex="0" Width="10%">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="Name" VisibleIndex="1" Width="30%">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn Caption="Street" FieldName="Address" VisibleIndex="2" Width="30%">
<DataItemTemplate>
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Text='<%#Eval("Address.Street")%>' Width="100%"></dx:ASPxTextBox>
</DataItemTemplate>
</dx:CardViewTextColumn>
<dx:CardViewTextColumn Caption="City" FieldName="Address" VisibleIndex="3" Width="33%">
<DataItemTemplate>
<dx:ASPxTextBox ID="ASPxTextBox2" runat="server" Text='<%#Eval("Address.City")%>' Width="100%"></dx:ASPxTextBox>
</DataItemTemplate>
</dx:CardViewTextColumn>
</Columns>
</dx:aspxcardview>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="SelectData" TypeName="Person">
</asp:ObjectDataSource>
</div>
</form>
</body>
</html>