Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Như bạn thấy, mã không phải là phức tạp, nhưng nó đòi hỏi rằng bạn hiểu như thế nào DataList (và điều khiển mẫu). Để hoàn thành kịch bản, chúng ta cần để cho bạn thấy làm thế nào để làm cho tiêu đề (footer). Các danh sách sau đây có chứa mã. | TECHNIQUE 32 The first application 125 private static MetaModel s_defaultModel new MetaModel public static MetaModel DefaultModel get return s_defaultModel public static void RegisterRoutes RouteCollection routes ContextConfiguration config new ContextConfiguration ScaffoldAllTables true DefaultModel.RegisterContext typeof NorthwindEntities config VB Public Class Global Inherits System.Web.HttpApplication Private Shared s_defaultModel As New MetaModel Public Shared ReadOnly Property DefaultModel As MetaModel Get Return s_defaultModel End Get End Property Public Shared Sub RegisterRoutes ByVal routes As RouteCollection Dim config As New ContextConfiguration config.ScaffoldAllTables True -- Shows all tables DefaultModel.RegisterContext GetType NorthwindEntities -- ObjectContext config End Sub End Class In this example we re using Entity Framework but with LINQ to SQL both the code and the concepts are identical. The ScaffoldAllTables property is important because by default its value is false. By setting it to true you ll automatically show all the tables in the first page. When you create a new application based on this project you ll notice that all the code is already in place and you don t need to write it A new route is also registered C routes.Add new DynamicDataRoute table action .aspx Constraints new RouteValueDictionary new action List Details Edit Insert Model DefaultModel VB routes.Add New DynamicDataRoute table action .aspx With .Constraints New RouteValueDictionary New With 126 Chapter 5 Data binding in ASP.NET Web Forms .Action List Details Edit lnsert .Model DefaultModel Dynamic Data controls work with a friendly URL such as Products List.aspx. You can change the generated URL to reflect your needs. You can protect these URLs using standard authorization and authentication features from ASP.NET such as UrlAutho-rization and FormsAuthentication. When you re running the project you ll receive a list of tables shown in figure 5.12. If you navigate to each