FormView Insert Session value
am 16.04.2008 23:50:41 von d-42
Hi,
I'm trying to use FormView to Insert an Object to an ObjectDataSource.
The insert method signature is simply:
void DALObject.InsertPerson(Person myObject)
The person object for the sake of argument is:
class Person {
// properties:
string FirstName // self explanatory
string LastName
long PersonID // "identity" (set by the database)
long AccountID // a related account id, needs to be set
}
The formview collects first name, last name, etc, and when I hit
insert, it automagically creates a Person object with the bound fields
set..
First Name:
Text='<%# Bind("FirstName") %>' />
...etc for lastname, then buttons, etc...
But one of the fields I need set is a session variable that contains
the AccountID to use.
How do I get it to create the object to be inserted and assign the
AccountID to the session variable. An additional constraint is that I
do not want the AccountID to be visible on the page.
I'm stumped.
The only thing I've thought of is to catch the OnInsertingEvent, but
I'm not even really sure what to do with it. It doesn't give me the
Person object its going to insert... just a dictionary of Property and
Value pairs for the Person it will create to insert. I might be able
to manually add a key pair ... to the dictionary? {AccountID,
session"AccountID" } ?? Would that work? It seems pretty clumsy...
Surely there is a better way?
Thanks,
Dave
Re: FormView Insert Session value
am 17.04.2008 02:37:13 von d-42
On Apr 16, 2:50 pm, d-42 wrote:
> Hi,
>
> I'm trying to use FormView to Insert an Object to an ObjectDataSource.
>
> The insert method signature is simply:
>
> void DALObject.InsertPerson(Person myObject)
>
> The person object for the sake of argument is:
>
> class Person {
> // properties:
> string FirstName // self explanatory
> string LastName
> long PersonID // "identity" (set by the database)
> long AccountID // a related account id, needs to be set
>
> }
>
> The formview collects first name, last name, etc, and when I hit
> insert, it automagically creates a Person object with the bound fields
> set..
>
>
> First Name:
> Text='<%# Bind("FirstName") %>' />
> ...etc for lastname, then buttons, etc...
>
>
> But one of the fields I need set is a session variable that contains
> the AccountID to use.
>
> How do I get it to create the object to be inserted and assign the
> AccountID to the session variable. An additional constraint is that I
> do not want the AccountID to be visible on the page.
>
> I'm stumped.
>
> The only thing I've thought of is to catch the OnInsertingEvent, but
> I'm not even really sure what to do with it. It doesn't give me the
> Person object its going to insert... just a dictionary of Property and
> Value pairs for the Person it will create to insert. I might be able
> to manually add a key pair ... to the dictionary? {AccountID,
> session"AccountID" } ?? Would that work? It seems pretty clumsy...
>
> Surely there is a better way?
>
> Thanks,
> Dave
Follow up... for the record, manually adding a key pair to the
dictionary in the onInsertingEvent DOES work, but I still think its
clumsy... and would like to know if there is a better way?
Thanks again,
Dave