New Features of ASP. NET 3.5 extensions: ASP. NET Dynamic Data experience

Source: Internet
Author: User

 

Overview

ASP. NET 3.5 extensions CTP contains a new feature called "ASP. NET Dynamic Data support (Dynamic Data Support)", which allows us to skip writing a lineCodeQuickly build a data-driven website that uses the LINQ to SQL object model.

Create an ASP. NET Dynamic Data site

After ASP. NET 3.5 extensions is installed, you can see a dynamic data website in the create a project dialog box:

After creation, the project structure is as follows:

 

In the solution, there will be an app_shared folder, which contains subfolders such as dynamicdatafields and dynamicdatapages. Some template files are stored here, and you can use these template files to customize the appearance of the website, let's talk about this next article.

Add Data Model

Add a LINQ to SQL file. Take the petshop4 database as an example:

Enable dynamic data templates

Open Web. config, find the dynamicdata section, and set the enabletemplates attribute to true. The default value is false.

Running site

1. After the website is run, all data tables added to the data model are listed on the default homepage:

2. click categories to enter. A list page is generated for us. The data in categories is displayed, and the products column is automatically displayed based on the foreign key relationship. You can navigate to the product corresponding to category and

3. built-in paging support and display the number of records that can be displayed on each page:

4. filter conditions are automatically listed based on the primary and Foreign keys:

5. The supplier is automatically listed on the editing page:

6. automatically generated new data page:

7. built-in data verification support:

Conclusion

After reading the above results, do you feel a little excited? Try it now :). In the ASP. NET Dynamic Data experience section, I will learn how to further customize the website.

 

 

 

Overview

In ASP. net 3.5 extensions new feature: Asp. NET Dynamic Data experience (I) briefly introduces ASP. net dynamic data to generate a data view page effect. In this article, let's take a look at how to further customize our website.

Customize website appearance

First, you can start customization in the simplest way. There is a masterpage. Master three CSS style files under the website. You can start from here to modify the overall appearance of the website. Modify the masterpage to make it look as follows:

Custom Dynamic Data View

To customize the dynamic data view, you can modify pages under app_shared/dynamicdatapages. For example, you can modify listdetailstemplate. aspx to add a title for each part of the page:

In addition, we can customize the data view for specific tables, add a products folder under the website (note that it must be the same as the table name), and add a listdetail. on the ASPX page, the detail information is not displayed. When you open products, the displayed page does not contain the detail information:

The URL access method is ~ /{Table}/{viewname}. aspx, which is specified in Web. config:

 <  Dynamicdata  Datacontexttype  = "" Enabletemplates  = " True " > <  Mappings  Querystringkeyprefix = "" Pattern  = " ~ /{Table}/{viewname}. aspx " > <  Add  Actions  = " List, details " Viewname  = " Listdetails " Templatefile  = " Listdetailstemplate. aspx "/> <! --  <Add actions = "list" viewname = "list" templatefile = "listtemplate. aspx "/> <add actions =" details "viewname =" details "templatefile =" detailstemplate. aspx "/>  --> <! --  Special overriding cases <add actions = "list, details" tables = "products, categories" viewname = "specialname" templatefile = "listtemplate. aspx "/> <add actions =" list "tables =" Products "templatefile =" detailstemplate. aspx "Path = "~ /Custompath. aspx "/> <add actions =" list "tables =" orders "viewname =" mylistviewname "/>  --> </  Mappings  > </  Dynamicdata > </  System. Web. Extensions  > 
Custom dynamic data fields

To customize dynamic data fields, you can modify the user control under app_shared/dynamicdatafields. For example, open text_edit.ascx and add a background color for the textbox:

<ASP:TextboxID= "Textbox1"Runat= "Server"Text='<%# Datavalue%>'Backcolor= "# Fddcbms"> </ASP:Textbox>

 

Run the website again. You can see the following during data editing:

Create dynamic data fields by yourself

In addition to using the above method to customize dynamic data fields, you can also create a dynamic data field by yourself and add a dynamic data field under app_shared/dynamicdatafields:

You can see that the control inherits from the fieldtemplateusercontrolbase class, add a label control in it, and set its foreground color to Red:

 <%  @  Control  Language  = "C #"  Inherits  = "System. Web. dynamicdata. fieldtemplateusercontrolbase"  %>  <  ASP  :  Label  ID = "Currentvalueid"  Runat  = "Server"  Text  ='  <% # Datavaluestring %>  '  Forecolor  = "# Ff0000"> </  ASP  :  Label  > 

 

To associate fields and controls in a data table, you must add a pratial class, which is specified using the renderhint feature. The first parameter is a field, and the second parameter is the control associated with it:

[Renderhint("Status","Statuscontrol")]Public partial classItem{}

Then run the website and enter the item data view. You can see that the foreground color of status changes to Red:

Custom Data Verification

Built-in support for data verification in ASP. NET Dynamic Data. You can also perform custom data verification. Add a pratial class. The built-in verification features include range, RegEx, and require, as shown in the following code:

 
UsingSystem;UsingSystem. Web. dynamicdata ;[Range("QTY", 100,100 0, errormessage ="Qty must be between {1} and {2")]Public partial classInventory{}

If the input is less than 100 or greater than 1000 during running, a prompt is displayed:

If the above features are not enough, you can also use the local method onpropertychanging in LINQ to SQL for verification, as shown in the following code:

 
Public partial classProduct{Partial voidOnproductnamechanging (StringValue ){If(!Char. Isupper (value [0]) {Throw newException("Product name must start with an uppercase letter .");}}}

 

Conclusion

About the new feature dynamic data support in ASP. NET 3.5 extensionsArticleThis article will introduce other features later.

 

Author: terrylee
Source: http://terrylee.cnblogs.com
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.