ASP.NET DomainDataSource with DetailsView not working at all RRS feed

  • General discussion

  • Hello,

    I have a DomainDataSource control on my asp.net web form, and I have bound a DetailsView control to it.  They are both set to allow updating.

    The DetailsView control has a sub-set of columns (I only want to display and allow the users to change a small set of columns that are in my domain data source).

    I have attached the OnUpdating event handler to the domain data source.  When I examine the Entity and OriginalEntity attributes in the event args, only the values that have been bound to details view have been seeded - all other properties of the entity are null.  This causes a big problem in my data context because the change gets thrown down to the data context and many of the columns which are now null are throwing an exception.

    My expectation is that the DomainDataSource control will maintain the entire entity that it has been given, and when I bind a DetailsView control to it, it will only affect the fields that are bound, leaving the rest of the unbound fields alone - not setting them to null.  I would also expect that in the OnUpdating event handler of the domain data source that the original entity would be the full entity, not the entity with most of the columns nulled out.

    Is this a problem with viewstate?  Is there a workaround?  I haven't been able to find any documentation on the asp.net domain data source yet.

    Shan McArthur

    Here is my ASP.NET code:

    <asp:DomainDataSource runat="server" ID="CompanyDS" DomainServiceTypeName="xlr8Portal.CompanyDomainService"
    SelectMethod="GetMyCompany" EnableUpdate="true" OnUpdating="CompanyDS_Updating">

    <asp:DetailsView ID="DetailsView" DataSourceID="CompanyDS" runat="server" AutoGenerateRows="false" AutoGenerateEditButton="true" DataKeyNames="AccountID">
    <asp:BoundField DataField="AccountID" InsertVisible="false" ReadOnly="true" />
    <asp:BoundField DataField="Name" HeaderText="Company Name" />
    <asp:BoundField DataField="WebSite" HeaderText="Website" />

    And here is my code-behind for the page: 

    namespace xlr8Portal
    public class CompanyDomainService : Xlr8DomainService
    public IQueryable<Company> GetMyCompany()
    var contact = SiteContext.Current.CurrentUserContact as Adxstudio.Xrm.Core.Contact;
    var company = contact.ParentCustomerAccount;
    if (company != null)
    return Context.Companies.Where(c => c.AccountID == contact.ParentCustomerAccountID.Value);
    return null;

        public partial class ManageCompanyPage : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e) {}

    public void CompanyDS_Updating(object sender, System.Web.DomainServices.WebControls.DomainDataSourceOperationEventArgs e) {}

    Friday, June 26, 2009 5:54 PM

All replies