Microsoft ASP.NET 4 : Dynamic Data Controls

9/24/2012 7:26:01 PM
The ASP.NET Dynamic Data framework provides six controls that specifically support Dynamic Data. These controls make up the core of ASP.NET Dynamic Data functionality. Here's a rundown of the Dynamic Data controls:
  • DynamicControl The DynamicControl control displays content defined in templated data-bound controls  using ASP.NET Dynamic Data features.

  • DynamicDataManager The DynamicDataManager is a nonvisual control that manages the dynamic behavior of the controls that support Dynamic Data.

  • DynamicEntity The DynamicEntity control represents an entity for use by ASP.NET Dynamic Data.

  • DynamicFilter The DynamicFilter control displays the user interface (UI) for filtering table rows using a specified column.

  • DynamicHyperLink The DynamicHyperLink control displays links to table actions such as edit, delete, and insert.

  • DynamicValidator The DynamicValidator control manages exception handling and error message display for those exceptions thrown in a data model.

These controls fit into the ASP.NET infrastructure—just like the rest of the server-side controls. The following exercise illustrates how to develop a Dynamic Data Web site.

Developing a Dynamic Data site

  1. Start Visual Studio. Create a new ASP.NET Project using the ASP.NET Dynamic Data LINQ To SQL template. Name the project DynamicDataLinqToSQLSite, as shown here:

  2. Visual Studio generates a Web Project primed to use Dynamic Data. Look at the items in Solution Explorer.

  3. Borrow the ASPNETStepByStep4.mdf file .

  4. Build a data model for the application. Right-click the project node from within Solution Explorer, and click Add, New Item. Select the Linq To SQL Classes template from the Installed Templates (Data node). Name the Linq To SQL class (to be generated by Visual Studio) DotNetReferences, as shown in the following graphic:

  5. Open Server Explorer and expand the ASPNETStepByStep4 database under the Data Connections node. Open the Tables node and find the DotNetReferences table. Visual Studio will display the Object Relational Designer surface automatically. Drag the DotNetReferences table from Server Explorer into the Object Relational Designer, as shown here (Visual Studio is showing that it will create a class named DotNetReference):

  6. Visual Studio adds a file named DotNetReferences.dbml to your project (along with some useful classes). Save this file.

  7. Open the Global.asax file. Find the code that registers the data context with the default data model. It will be commented out. Uncomment the line and have the DefaultModel register the DotNetReferencesDataContext (which was generated by Visual Studio), as shown in the following code. Also set the ScaffoldAllTables parameter to true.

    public static void RegisterRoutes(RouteCollection routes)
        new ContextConfiguration() { ScaffoldAllTables = true});
      // more registration code...

  8. Now run the site. The default page will appear like this:

  9. Click the DotNetReferences link that appears under the My Tables banner. Visual Studio reflected on the data in the data model and populated a GridView based on the data. (In fact, if you read the source code of Default.aspx, you can see only a GridView—you see the source code in the next step.) You should this in your browser when you click the DotNetReferences link:

  10. Open the Default.aspx file and look at what Visual Studio produced for you:

    <asp:GridView ID="Menu1" runat="server" AutoGenerateColumns="false"
      CssClass="DDGridView" RowStyle-CssClass="td" HeaderStyle-CssClass="th"
        <asp:TemplateField HeaderText="Table Name" SortExpression="TableName">
            <asp:DynamicHyperLink ID="HyperLink1"
              runat="server"><%# Eval("DisplayName") %>

  11. This code generates a table of hyperlinks based on the default data model (which is made up of a single table right now). When you click the link, ASP.NET directs the request to a file named List.aspx. You can find List.aspx in the DynamicData\PageTemplates node of the project in Solution Explorer. ASP.NET substitutes the display name (the DotNetReferences) in the URL and uses the data to produce a listing of the contents of the DotNetReferences table. If you open the List.aspx file, you also find a GridView—this GridView in List.aspx produces the listing of the table contents.

Top 10
3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
3 Tips for Maintaining Your Cell Phone Battery (part 1) - Charge Smart
OPEL MERIVA : Making a grand entrance
FORD MONDEO 2.0 ECOBOOST : Modern Mondeo
BMW 650i COUPE : Sexy retooling of BMW's 6-series
BMW 120d; M135i - Finely tuned
PHP Tutorials : Storing Images in MySQL with PHP (part 2) - Creating the HTML, Inserting the Image into MySQL
PHP Tutorials : Storing Images in MySQL with PHP (part 1) - Why store binary files in MySQL using PHP?
Java Tutorials : Nested For Loop (part 2) - Program to create a Two-Dimensional Array
Java Tutorials : Nested For Loop (part 1)
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
Popular Tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS