Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 09, 2012 09:07 AM by micmac
Jun 01, 2009 04:28 PM|LINK
Is there anybody having sample of templates to add "clone/copy" functionality to ASP.NET dynamic data? I would like to clone/copy existing record into new one and insert to the table with new primary key. Click on "Clone"/"Copy" link next to edit/delete/details
should display identical original record content and click on "Update" link insert such record to the underlying table.Thank you.
Custom Page Templates
Jun 01, 2009 04:49 PM|LINK
I've done it but not generically I did a custom page for each page I wanted this on.
Jun 01, 2009 07:36 PM|LINK
Do you have some sample posted somewhere?
Jun 01, 2009 09:00 PM|LINK
Well to put it simply what I did was copy an Edit page into a custom Pages folder, then add a button for copy/clone and in the click event take all the fields and create a new one and then insert it into the DB.
protected void btnCopyProduct_Click(object sender, EventArgs e)
var DC = new BFDataContext();
int pf_id = (int)FormView1.SelectedValue;
var product = DC.bf_products.FirstOrDefault(p => p.pf_id == pf_id);
var copyProduct = new bf_product()
Accessories = product.Accessories,
active = product.active,
AddtoRooms = product.AddtoRooms,
attr_label1 = product.attr_label1,
attr_label2 = product.attr_label2,
attr_label3 = product.attr_label3,
attr_label4 = product.attr_label4,
attr_label5 = product.attr_label5,
CategoryID = product.CategoryID,
Color = product.Color,
cost = product.cost,
DateEntered = product.DateEntered,
description = product.description,
Features = product.Features,
Height = product.Height,
image_file = product.image_file,
image_height = product.image_height,
image_width = product.image_width,
ItemType = product.ItemType,
lastmodified = product.lastmodified,
Length = product.Length,
list_price = product.list_price,
ManufacturerID = product.ManufacturerID,
ManufacturerURL = product.ManufacturerURL,
Model = product.Model,
// increment name to prevent identical products
name = "COPY - " + product.name, // + "_" + i,
ObjectModel = product.ObjectModel,
OwnerID = product.OwnerID,
PreviousModel = product.PreviousModel,
sdesc = product.sdesc,
Size = product.Size,
Sku = product.Sku,
SpecialRemarks1 = product.SpecialRemarks1,
Style = product.Style,
Type = product.Type,
Weight = product.Weight,
Width = product.Width
// goto the new product
Jun 02, 2009 01:33 PM|LINK
Yes, it does. Thank you for your help.
Jun 03, 2009 05:43 PM|LINK
I've found much better generic solution done by member of CodePlex. See it at http://n41dynamicdataex.codeplex.com/.
Jun 04, 2009 05:25 AM|LINK
Thanks for the link to the Clone Extender. I'm going to add it to the
Dynamic Data FAQ
Dec 01, 2009 02:43 PM|LINK
Can you think of a way to do this without inserting the record in the database first?
I have custom pages derived from the standard DD ones, one is a View/Edit page and another is an Insert page all using FormView's with DynamicControls.
I have a button on the View/Edit page that when clicked I want it to redirect to the Insert page but with all the fields filled in from the data on the original record.
I don't want this data inserted into the database until the user clicks the Insert button on the Insert page. The reason for this is I want to copy across some but not all the fields from the source record, and force the user to enter values for the ones
that are not copied across. This is because some of the fields have Unique constraints.
I can obviously understand how to clone records easily, but what I dont get is how to get the Insert page to show the data to edit in Insert mode since it is a FormView using DD controls so they cannot easily be manipluated in the codebehind.
Dec 01, 2009 05:21 PM|LINK
Hi Steaddyman, yes I can but its a pain pass all the propert values in the query string and ad an insert default check see:
this post seems to have been moved or deleted.
Also in the Futures and .Net 4.0 Beta 2 there is a way of passing in an object with the default values in it using: the FormView extension method SetMetaTable() to pass in the default values object.
Dec 02, 2009 09:45 AM|LINK
Thanks for your response. The second link above seems to be incorrect and just points back to this post.
My plan was to pass the PK_id of the source recrod to copy to my insert page and then have that populate all the controls on the Page_Load or some other event.
But my problem is all these controls are dynamic controls and I would need to resort to messy FindControl methods to implement it that way. I was kind of hoping there was a way to hack into the existing session / postdata to populate the controls but don't
understand it well enough.
I also wasn't sure how to prevent this posted data reseting the controls back to that state when a validation error occurs.