• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Display in DetailsView by object source when an object contains another object

namespace FLX.FlexiChips.App
{
    using System;
    using System.Data;
    using System.IO;
    using System.Text;
    using System.Configuration;
    using System.Collections.Generic;
    using System.Collections.Specialized;

    [Serializable()]
    /// <summary>
    /// Summary description for Address
    /// </summary>
    public class Address
    {

        #region constructors
        //=======================================================================
        public Address(){}
        //=======================================================================
        public Address(
            string addressLine1,
            string addressLine2,
            string citySuburb,
            string state,
            string postCode)
        {
            this.AddressLine1 = addressLine1;
            this.AddressLine2 = addressLine2;
            this.CitySuburb = citySuburb;
            this.PostCode = postCode;
        }
        //=======================================================================
        #endregion

        #region Fields
        //====================================================================================
        private string _addressLine1 = String.Empty;
        private string _addressline2 = String.Empty;
        private string _citySuburb = String.Empty;
        private string _state = String.Empty;
        private string _postCode = String.Empty;
        //====================================================================================
        #endregion

        #region Properties
        //================================================================================
        public string AddressLine1
        {
            get { return _addressLine1; }
            set { _addressLine1 = value; }
        }
        //================================================================================
        public string AddressLine2
        {
            get { return _addressline2; }
            set { _addressline2 = value; }
        }
        //================================================================================
        public string CitySuburb
        {
            get { return _citySuburb; }
            set { _citySuburb = value; }
        }
        //================================================================================
        public string State
        {
            get { return _state; }
            set { _state = value; }
        }
        //================================================================================
        public string PostCode
        {
            get { return _postCode; }
            set { _postCode = value; }
        }
        //================================================================================
        #endregion
    }
}


 public class ContactInfo
    {
        #region Constructor
        //=============================================================================
        public ContactInfo() { }
        //=============================================================================
        public ContactInfo(
            Address contactAddress,
            string workPhone,
            string homePhone,
            string mobilePhone,
            string faxNumber,
            string emailAddress)
        :this(new Address(),contactAddress,workPhone,homePhone,mobilePhone,faxNumber,emailAddress,String.Empty){}
        //=============================================================================
        public ContactInfo(
            Address streetAddress,
            Address contactAddress,
            string workPhone,
            string homePhone,
            string mobilePhone,
            string faxNumber,
            string emailAddress,
            string description)
        {
            this.StreetAddress = streetAddress;
            this.ContactAddress = contactAddress;
            this.WorkPhone = workPhone;
            this.HomePhone = homePhone;
            this.MobilePhone = mobilePhone;
            this.FaxNumber = faxNumber;
            this.EmailAddress = emailAddress;
            this.Description = description;
        }
        //=============================================================================
        #endregion

        #region Fields
        //=============================================================================
        private Address _streetAddress  = new Address();
        private Address _contactAddress = new Address();
        private string _workPhone       = String.Empty;
        private string _homePhone       = String.Empty;
        private string _mobilePhone     = String.Empty;
        private string _faxNumber       = String.Empty;
        private string _emailAddress    = String.Empty;
        private string _description     = String.Empty;
        //=============================================================================
        #endregion

        #region Properties
        //==============================================================================
        public Address StreetAddress
        {
            get { return _streetAddress; }
            set { _streetAddress = value; }
        }
        //==============================================================================

        public Address ContactAddress
        {
            get { return _contactAddress; }
            set { _contactAddress = value; }
        }
        //==============================================================================

        public string WorkPhone
        {
            get { return _workPhone; }
            set { _workPhone = value; }
        }
        //==============================================================================

        public string HomePhone
        {
            get { return _homePhone; }
            set { _homePhone = value; }
        }
        //==============================================================================
        public string MobilePhone
        {
            get { return _mobilePhone; }
            set { _mobilePhone = value; }
        }
        //==============================================================================
        public string FaxNumber
        {
            get { return _faxNumber; }
            set { _faxNumber = value; }
        }
        //==============================================================================
        public string EmailAddress  
        {
            get { return _emailAddress; }
            set { _emailAddress = value; }
        }
        //==============================================================================
        public string Description
        {
            get { return _description; }
            set { _description = value; }
        }
        //==============================================================================
        #endregion
    }
}

 <asp:TableCell>
                        <asp:DetailsView id="dtviewSalesStateAddress"  DataSourceID="ObjectDataSource1" HeaderText="Contact Information" AutoGenerateRows="false" runat="server">
                        <Fields>
                            <asp:BoundField   DataField=AddressLine1 HeaderText="SteetAddress"/>
                            <asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress"/>
                            <asp:BoundField DataField="FaxNumber" HeaderText="FaxNumber"/>
                        </Fields>
                        </asp:DetailsView>
                        <asp:ObjectDataSource runat="server" ID="ObjectDataSource1" TypeName="FLX.FlexiChips.Web.Util" SelectMethod="GetAddressByStateID">
                          <SelectParameters>
                                <asp:ControlParameter Name="stateID" PropertyName="SelectedValue" ControlID="dropDownSalesState"></asp:ControlParameter>
                            </SelectParameters>
                        </asp:ObjectDataSource>
                    </asp:TableCell>


I want to display SreetAddress.AddressLine1 in ContactInfo object.

Can anyone let me know how to access it straight away in <asp:BoundField DataField=??????> as i don't want to write any code behind.

Thanks,
0
life_j
Asked:
life_j
1 Solution
 
dstanley9Commented:
I don't think you can access child classes with BoundField.  You can use a TemplateField and Eval:

                    <asp:TemplateField HeaderText="SteetAddress">
                        <ItemTemplate>
                            <asp:Label ID="SteetAddressLabel" runat="server" Text='<%# Eval("SreetAddress.AddressLine1 ") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="SteetAddressTextBox" runat="server" Text='<%# Eval("SreetAddress.AddressLine1 ") %>'></asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateField>

The bad news is that Eval() is a one-way data binding, so if the user enteres in an address in the text box (when in edit mode) you'll have to capture that value in code-behind.
0
 
life_jAuthor Commented:
Hello that works. Just letting  you that i have found another answer for my question.

Expose the properties in the address class to the properties in the contactinfo class

public Address sAddressLine1

{


get { return _streetAddress.AddressLine1; }


set { _streetAddress.AddressLine1 = value; }

}

public Address cAddressLine1

{


get { return _contactAddress.AddressLine1; }


set { _contactAddress.AddressLine1 = value; }

}
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now