Solved

Accessing fields when updating from formvie/objectdatasource

Posted on 2009-05-20
2
196 Views
Last Modified: 2013-12-17
Greetings all

I have a page with two formviews on it - fvPeople and fvAddress. Each is linked to its own objectdatasource (with DataObjectTypeName set to a class taht defiens all the fields). The fvPeople is the "owner" of the address.

The ODS for fvAddress contains a field called People_Link which is the Id of the People record. This field is not displayed within the formview. Updating an existing address record for a People record works fine, but when it comes to inserting an Address record then I run into trouble  -- I can't pass the People record's Id to the Insert procedure of the ods -- if I define the method as "InsertAddress(AddressODS_DO addr, int InsertCoupleId) --  it complains about being unable to find a generic method that takes just "AddressODS_DO" as paremeter.

As an experiment, I placed the "People_Link" field in the InsertTemplate, making it invisible. This seems to work -- just not sure how acecptable this is?

Any thoughts on how to get around this?


In advance, thanks!!!

    allanmark


SOURCE:

 

<asp:ObjectDataSource ID="addressODS" runat="Server" SelectMethod="GetResidential" TypeName="BusinessLogic.Business"

            DataObjectTypeName="DataTransferObjects.AddressODS_DO" InsertMethod="AddressODS_Insert" OnInserting="AddressODS_Inserting"

        UpdateMethod="AddressODS_Update" OnUpdated="AddressODS_Updated" OnSelecting="addressODS_Selecting" >

        <SelectParameters >

            <asp:QueryStringParameter Name="CoupleId"  DbType="Int32" Direction="Input" DefaultValue="0"  />                

        </SelectParameters>

        <InsertParameters>

            <asp:QueryStringParameter Name="InsertCoupleId"  DbType="Int32" Direction="Input" DefaultValue="0"  />                

        </InsertParameters>

            

    </asp:ObjectDataSource>    

 

 

 

CODE BEHIND:

 

public static bool AddressODS_Insert(AddressODS_DO address, int AddressODS_DO)

        {

            bool insertStatus;

            

            insertStatus = DataAccess.ApplyInsertAddress(address);

 

            return insertStatus;

        }

Open in new window

0
Comment
Question by:allanmark
2 Comments
 
LVL 15

Accepted Solution

by:
NazoUK earned 250 total points
ID: 24432072
When using DataObjects your update / insert record can only have one parameter which must be of that type. I'm assuming that InsertCoupleId is a property of this datatype?

You can manipulate the dataobject before it is passed to the update / insert routine through the Updating / Inserting events of the objectdatasource, both of which have the same delegate parameters:

(object sender, ObjectDataSourceMethodEventArgs e)

so you could add: OnInserting = "addressODS_Inserting" to your ObjectDataSource, then:

protected void addressODS_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
    {
        DataTransferObjects.AddressODS_DO obj= (DataTransferObjects.AddressODS_DO)e.InputParameters[0];
        obj.InsertCoupleID = Whatevervalue;
    }
0
 

Author Closing Comment

by:allanmark
ID: 31583504
100%!!!  Many thanks!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now