GetNewFromTemplate() public method

Create a new non-persisted Data View using an existing Data View as a template.
public GetNewFromTemplate ( int dataViewId ) : DataView
dataViewId int The identifier of a Data View to use as a template for the new Data View.
return DataView
Example #1
0
        /// <summary>
        /// Handles the Click event of the Copy button control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnCopy_Click( object sender, EventArgs e )
        {
            // Create a new Data View using the current item as a template.
            var id = int.Parse( hfDataViewId.Value );

            var dataViewService = new DataViewService( new RockContext() );

            var newItem = dataViewService.GetNewFromTemplate( id );

            if (newItem == null)
                return;

            newItem.Name += " (Copy)";

            // Reset the stored identifier for the active Data View.
            hfDataViewId.Value = "0";

            ShowEditDetails( newItem );
        }