Use the variable as the key value for FormView Insert


This sounds really simple and for the life of me I can not find out how to do this. I have a FormView where the user can create a new contact. I am passing into this page a key variable. In the insert statement I need to have this key be part of the insert statement. It is currently defined as a public variable in my cs file but how do I use it as a parameter? This key does not show up on the FormView. All of my insert work is done on the ASP page.

Since you have the key value in your code-behind already, just handle the FormView ItemInserting event. You can access the values being inserted like this:

void myFormView_ItemInserting(Object sender, FormViewInsertEventArgs e)
    e.Values["columnName"] = yourKeyValueHere;

Where "columnName" is where you want to put the name of the column that your key value should be inserted into, and "yourKeyValueHere" is where the variable containing your keyvalue should go.

Let me know if you have any questions.