Solved

Accessing fields when updating from formvie/objectdatasource

Posted on 2009-05-20
2
197 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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