What is the best way to implement "Copy to new" functionality with FormView control and content templates
I have a FormView control in an ASP.NET page. I use the InsertItemTemplate and EditItemTemplate to provide data manipulation functionality, and it is working very well. I would lik开发者_运维百科e to allow the user to "Copy to new" from an existing item. In other words, I want the user to be able to display an item as if they are going to edit it, then, if they click a "Copy to new" button, it will load the information from that item into an "Insert" form so they could just change the bits of data that they want, and insert the new item.
The data objects we are dealing with are fairly large so, providing this functionality will save the user a lot of data entry misery.
I have experimented with copying the existing EditItemTemplate controls in the Copy button's click event, storing them, and writing them to the new InsertItemTemplate controls, once the form is reloaded (in the Page_PreRender event). But this is pretty ugly stuff. There has to be a better/simpler way.
Does anyone have any suggestions?
Thanks very much for whatever advice you can give.
Well, why not just leave it in edit view, have Copy to new set a flag, then handle the ItemEditing event, and if in copy to new mode, then you insert a new record instead of proceeding with the update. That might save you a lot of work.
HTH.
精彩评论