Solved

Accessing fields when updating from formvie/objectdatasource

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 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