?
Solved

Accessing fields when updating from formvie/objectdatasource

Posted on 2009-05-20
2
Medium Priority
?
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
NazoUK earned 1000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

770 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