D
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..
<InsertItemTemplate>
First Name: <asp:TextBox ID="tbFirstNAme" runat="server"
Text='<%# Bind("FirstName") %>' /><br />
...etc for lastname, then buttons, etc...
</InsertItemTemplate>
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
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..
<InsertItemTemplate>
First Name: <asp:TextBox ID="tbFirstNAme" runat="server"
Text='<%# Bind("FirstName") %>' /><br />
...etc for lastname, then buttons, etc...
</InsertItemTemplate>
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