Monday, 16 March 2009

Adding Dynamic Data Previews to a New or Exiting Dynamic Data Website

What I want to do here is create a template website I can copy and reuse to build web sites based on the Preview. Hope this is of some help.

Create a new Dynamic Data Web Site:

ScreenShot248

Once created empty the DynamicData folder (keeping the folder) remove all sub folders.

Copy the contents of the following folders to the Dynamic Data Folder for:

Linq to SQL Web Sites

Linq to SQL folders

Entity Framework Web Sites

Entity Framework folders

Once you’ve copied the files

Copied folders

It’s time to do some editing of the files, we’ll use the Ctrl+Shift+H to do a search and replace of files in folders.

Setting up Look in folder

In the Find and Replace dialogue click the ellipsis (…) button at the end of the Look in: drop down list.

  1. Find the root folder of your website.
  2. Select the DynamicData folder in your site.
  3. Add to the Selected folders.

Find and Replace dialogue

Using the Search Patterns list below fill in the Find and Replace dialogue box:

  1. Search for pattern.
  2. Replace with pattern.
  3. Use regular expression.
  4. Enter the file type to search in.

Search patterns:

step Search for: Replace with: Use Regular expressions file types
1. namespace DynamicData(EF)*Project \{\n   yes *.ascx.cs
2. \}\n\} \} yes *.ascx.cs
3. Inherits="DynamicData(EF)*Project.   Yes *.ascx
4. CodeBehind=" CodeFile=" No *.ascx

In step 1 & 3 you may encounter any of the following name spaces to match and remove:

  1. DynamicDataProject.DynamicData.Filters {
  2. DynamicDataProject.DynamicData.EntityTemplates {
  3. DynamicDataProject.DynamicDataL2S.EntityTemplates {
  4. DynamicDataProject {
  5. DynamicDataEFProject {

I would attempt to remove them in the order shown above (4 & 5 are covered by the pattern namespace DynamicData(EF)*Project \{\n

 Finally Add a Reference to the Preview DLL’s

  1. Right click the root of the website, and choose “Add Reference…”
    Add reference to web site
  2. In the “Add Reference” dialogue browse to the Common Files folder in the location where you unzipped the Preview. Then select all the dll’s and click OK to add a reference to them in your web site.
    Add reference dialogue

Finally copy the:

File Copy to Folder
AutocompleteFilter.asmx.cs App_Code folder (create if you have not already).
AutocompleteFilter.asmx ~/ (root of website)
AjaxToolkitFixes.css ~/ (root of website)
AutocompleteStyle.css ~/ (root of website)
Site.css ~/ (root of website)
Site.master ~/ (root of website)
Site.master.cs ~/ (root of website)
web.config ~/ (root of website)

 

Similar editing is now required of these files see the Search Patterns above.

Edit the web.config and remove the contents of the connection strings node in the web.config

remove connection strings from web.config

Finally tweak the GridView  on the Default.aspx page.

<asp:GridView ID="Menu1" 
    runat="server" 
    AutoGenerateColumns="false" 
    CssClass="DDGridView"
    RowStyle-CssClass="td" 
    HeaderStyle-CssClass="th" 
    CellPadding="6">

See the BOLD ITALIC text this is to take advantage of the friendlier CSS now supplied with the Preview it won’t stamp on other CSS you may want to use in your web site as the CSS in the .Net 3.5 SP1 version does.

Now you have a sample that you can use over an over like a template

Your next step is the same as if you had just done file new “Dynamic Data Web Site” but I would copy to a new folder first so I can use this as a template each time I want a Preview DD website.

Happy coding

I’m a an MVP and I’m a PC

No comments: