Saturday, March 24, 2012

Populate foreign key in InsertTemplate of FormView

Hello all,

How would I populate a foreign key value in a label field of a FormView when
FormView changes mode to Insert? So that I can insert foreign key.

Explanation:
Suppose there are two tables in database, EMPLOYEE (list of employees) and
EMPLOYEE_DOCS (list of documents of every employee). table EMPLOYEE_DOCS
have a foreign key field EMPLOYEE_ID. When I use FormView's Insert mode for
EMPLOYEE_DOCS, I want to to explicitly take foreign key, so that it wont go
blank when inserting in database or user wont need to type it. I have
everything in Panels (webcontrol)

Thank you for help.
MirajThanks all, I figured out

I did this:

Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
FormView1.ItemInserting

e.Values("EMPLOYEE_ID") =
GridView1.Rows(GridView1.SelectedIndex).Cells(1).T ext ' cells(1).text is the
foreign key

End Sub

"Miraj Haq" <mirajhaq-n-o-s-p-a-m@.yahoo.com> wrote in message
news:epbuhXYhFHA.1444@.TK2MSFTNGP10.phx.gbl...
> Hello all,
> How would I populate a foreign key value in a label field of a FormView
> when FormView changes mode to Insert? So that I can insert foreign key.
> Explanation:
> Suppose there are two tables in database, EMPLOYEE (list of employees) and
> EMPLOYEE_DOCS (list of documents of every employee). table EMPLOYEE_DOCS
> have a foreign key field EMPLOYEE_ID. When I use FormView's Insert mode
> for EMPLOYEE_DOCS, I want to to explicitly take foreign key, so that it
> wont go blank when inserting in database or user wont need to type it. I
> have everything in Panels (webcontrol)
> Thank you for help.
> Miraj

0 comments:

Post a Comment