2

I have a Formview binded in the code file to a generic list. Now, upon editing of a record, I wish to access the Keys and NewValues out of the FormViewUpdateEventArgs parameter of the ItemUpdating event handler method.

From what I've tried and searched over the internet as of now, I've come to know that updated values are only available if the Formview is set a data source control on the markup page else they'd be null. Is this true?

Secondly, at this moment I am casting the sender object to formview and individually filling each object property by using FindControl method to find and retrieve values present in the controls. Is this the best way to do this task?

As an example, this is what I am doing atm:

FormView currentForm = (FormView)sender;
ListObject.ID = new Guid(((HiddenField)(currentForm.FindControl("hdnID"))).Value);
ListObject.Name = ((TextBox)(currentForm.FindControl("txtName"))).Text;

Thanks for the help fellas!

Dienekes
  • 1,548
  • 1
  • 16
  • 24
  • 1
    FindControl is always "not the best way" to do things because it's kind of expensive. you should really use it as a last resort. In you case, I think you should realy consider to use an ObjectDataSource instead of directly bind it directly in your code – Simon Dugré Nov 01 '10 at 18:25

1 Answers1

0

Based on what your doing I would suggest you not use a FormView. FormView's are brilliant when working with datasources, but fail, when dealing with manual bound data the way you are, your basically overriding and manually building the form, and it would be simpler to just create a HTML form and ASP.Net Server Side Controls.

FindControl is an expensive operation and can become unwieldily. Simple assigning a value during the loop of your data to a server side control will be faster.

Alternatively as suggested, use a ObjectDataSource and bind your data to the FormView in that way.

BinaryMisfit
  • 29,219
  • 2
  • 37
  • 44