Download presentation
Presentation is loading. Please wait.
Published byNichole Doncaster Modified over 10 years ago
1
Internetteknologi (ITNET2) Presentation 21: ASP.NET Advanced
2
Ingeniørhøjskolen i Århus Slide 2 Agenda User Controls Master & Content Pages Data Binding (Databases, Collections & XML)
3
Ingeniørhøjskolen i Århus Slide 3 What is a User Control? User controls simplify the reuse of code and UI components within a Web application A user control is a user-defined Web server control with an.ascx extension Contains HTML, but not the,, or tags or Contains code to handle its own events
4
Ingeniørhøjskolen i Århus Slide 4 Why Use User Controls? Reuse user interface and code Must live in Web form! Page2.aspx Control1.ascx Page1.aspx Page3.aspx Application AApplication B
5
Ingeniørhøjskolen i Århus Slide 5 Master & Content Pages Structuring Mechanism Replaces “Include” Master Pages “includes” different Content Pages Master Pages attributes reachable from Content Pages Master.FooterText = "This is a custom footer"; AdRotator ad = (AdRotator)Master.FindControl("MyAdRotator");
6
Ingeniørhøjskolen i Århus Slide 6 Master & Content Pages Replacing placeholder content
7
Ingeniørhøjskolen i Århus Slide 7 Data Binding Goal: –To able to connect to data sources to obtain data –Relational Databases (SQL) –Object Databases and O/R mappers –XML files
8
Ingeniørhøjskolen i Århus Slide 8 Data Sources SqlDataSource –Enables binding to a SQL database represented by an ADO.NET provider, such as Microsoft™ SQL Server, OLEDB, ODBC, or Oracle. ObjectDataSource –Enables binding to a middle-tier object such as a data access layer or business component. AccessDataSource –Enables binding to a Microsoft™ Access (Jet) database. XmlDataSource –Enables binding to an XML file or document. SiteMapDataSource –Enables binding to the hierarchy exposed by an ASP.NET 2.0 site navigation provider.
9
Ingeniørhøjskolen i Århus Slide 9 Data Bound Controls GridView –Renders data in a grid format. This control is an evolution of the DataGrid control, and can automatically take advantage of data source capabilities. DetailsView –Renders a single data item in a table of label/value pairs, similar to the form view in Microsoft™ Access. This control can also automatically take advantage of data source capabilities. FormView –Renders a single data item at a time in a form defined by a custom template. Renders a single data item in a table of label/value pairs, similar to the form view in Microsoft™ Access. This control can also automatically take advantage of data source capabilities. TreeView –Renders data in a hierarchical tree view of expandable nodes. Menu –Renders data in a hierarchical dynamic menu (including flyouts).
10
Ingeniørhøjskolen i Århus Slide 10 Displaying Data from a RDBMS in a Grid View 1.Create a DB 2.Create a Connection to DB (Web.Config) 3.Create a SQL Data Source & Grid View <add name="Pubs“ connectionString="Server=(local);Integrated Security=True;Database=pubs;" providerName="System.Data.SqlClient" /> " /> http://www.asp.net/QuickStart/aspnet/samples/data/GridViewBoundFields_cs.aspxa
11
Ingeniørhøjskolen i Århus Slide 11 Paging & Sorting Paging is supported at GUI Sorting is supported at GUI Columns may be automatic or manually set up … …
12
Ingeniørhøjskolen i Århus Slide 12 Using a DAL public class MyDataLayer { public DataView GetRecords(); public DataView GetRecordsByCategory(String categoryName); public DataView GetRecordByID(int recordID); public int UpdateRecord(int recordID, String recordData); public int DeleteRecord(int recordID); public int InsertRecord(int recordID, String recordData); } Use an object as a DAL for controlled access to DB Server Control (ObjectDataSource) using MyDataLayer
13
Ingeniørhøjskolen i Århus Slide 13 Using a Business Logic Layer Provides us with a nice OO decoupling Value objects must have get/set methods http://www.asp.net/QuickStart/util/srcview.aspx?path=~/aspnet/samples/data/GridViewObject.src
14
Ingeniørhøjskolen i Århus Slide 14 Using the VS 5.0 DataSet Wizard DAL / BLL is tedious work VS 5.0 has wizard
15
Ingeniørhøjskolen i Århus Slide 15 Binding the DataTable to View Control A DataTable and a TableAdapter is constructed Add an ObjectDataSource –TypeName="DataSet1TableA dapters.personTableAdapter” Add a GridView and/or a FormView Server Control
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.