Solved

Accessing fields when updating from formvie/objectdatasource

Posted on 2009-05-20
2
195 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
Comment Utility
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
Comment Utility
100%!!!  Many thanks!!!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

8 Experts available now in Live!

Get 1:1 Help Now