AutoMapper a viable alternative to two way databinding using a FormView?

Posted by tbone on Stack Overflow See other posts from Stack Overflow or by tbone
Published on 2010-03-18T14:26:26Z Indexed on 2010/03/18 19:41 UTC
Read the original article Hit count: 588

Filed under:
|
|
|

I've started using the FormView control to enable two way databinding in asp.net webforms. I liked that it saved me the trouble of writing loadForm and unloadForm routines on every page. So it seemed to work nicely at the start when I was just using textboxes everywhere....but when it came time to start converting some to DropDownLists, all hell broke lose. For example, see: http://stackoverflow.com/questions/2435185/not-possible-to-load-dropdownlist-on-formview-from-code-behind ....and I had many additional problems after that.

So I happened upon an article on AutoMapper, which I know very little about yet, but from the sounds of it, this might be a viable alternative to two-way databinding a form to an domain entity object? From what I understand, AutoMapper basically operates on naming convention, so, it will look for matched names properties(?) on the source and destination objects.

So, basically, I have all my domain entities (ie: Person) with properties (FirstName, LastName, Address, etc)....what I would like to be able to do is declare my asp controls with those exact same names, and have automapper do the loading and unloading.

One obvious caveat is that AutoMapper would have to know the proper property name for each control type, ie:

Person.FirstName --> form.FirstName*.Text*
Person.Country --> form.Country.SelectedValue
Person.IsVerified --> form.IsVerified.Checked

....so it would have to have the smarts to find the control on the form, determine its type, and then load/unload between the domain object and the webform control into the proper property of the control.

So if this worked, a person could just get rid of the cursed FormView control entirely, and it would be just one line of code each for binding and unbinding a webform.

Possible?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about automapper