views:

149

answers:

2

I have a formview. With the datasource of the formview i want to insert a record into the database, but i want to insert a value i get from a method i create in code. Doesn't that mean that i will not be able to directly code this onto the Data source using the wizard?

+1  A: 

I don't think you can get the value directly from the method, but you can get dynamic values from:

  • QueryString
  • List item
  • Cookie
  • Control
  • Form value
  • Profile
  • Session

(See here for details ==> http://msdn.microsoft.com/en-us/library/xt50s8kz.aspx)

You could put the result of your method into one of these (i.e. hidden form field or Session for example) and still use the DataSource wizard to set it all up.

If this doesn't work for you, it's fairly easy to inject dynamic values into your inserts via the ItemInserting event of the FormView control.

WayneC
Using the ItemInserting event of the FormView or the Inserting event of the data source control are definitely the recommended ways of doing this. In each of those events you get a dictionary that contains all the currently known values from the UI and parameters. You can edit/add/remove items from the dictionary to tweak anything you want. You can even perform validation logic and cancel the operation if you want.
Eilon
A: 

i would use a control paramater with controlid=__PAGE and create a property that runs the code, i have had to do this numerous times.

Christopher Kelly