嗨我有一個類,其中包含用戶定義的數據類型屬性。我創建了該類的一個實例。當我將該類的該對象綁定到DetailsView時,它將顯示除用戶定義的數據類型屬性以外的所有屬性。這裏是示例代碼。如何將用戶定義的數據類型對象綁定到DetailsView?
public class Customer
{
public string CustomerName { get; set; }
public int Age { get; set; }
public Address CustomerAddress { get; set; }
}
Address class looks like
public class Address
{
public string Line1 { get; set; }
public string Line2 { get; set; }
public string City { get; set; }
}
Creating an object of Customer class
var cust = new Customer {
CustomerName = "abc",
Age = 25,
CustomerAddress = new Address{ Line1 = "abc", Line2 = "abc", City = "abc" }};
Binding cust to Details View
List<Customer> customerInfo = new List<Customer>();
customerInfo.Add(cust);
DetailsView1.DataSource = custmerInfo;
DetailsView1.DataBind();
In .aspx page
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False">
<Fields>
<asp:BoundField DataField="CustomerName" HeaderText="Customer Name">
<asp:BoundField DataField="Age" HeaderText="Customer Age">
<asp:BoundField DataField="CustomerAddress" HeaderText="Customer Address ">
</Fields>
</asp:DetailsView>
以上代碼未顯示客戶地址。誰能幫我 ?