4. Programatic DataBinding
Using Control Properties
◦ DataSource a collection (a
list, reader, dataset)
◦ DataTextField
◦ DataValueField
Don’t forget to DataBind();
6. Single-Value Binding
<%# expression goes here %>
Expression can be:
◦ A function (must be protected, public)
◦ A property (must be protected, public)
◦ A string literal or an mathematical
expression
Bound to
TextBox, Label, LinkButton,….etc
Must call Page.DataBind() or
Control.DataBind()
7. Repeated-Value Binding
Use DataSource to bind to collection
and Use DataTextField and
DataValueField to bind the Value and
Text of the control in the aspx
Never forget to call DataBind()
12. Data Source Controls
Directly connect to a database, execute
a query, loop through the records in the
result set, and display them on a page.
Designer Support
No data access code.
Includes:
◦ SqlDataSource
◦ ObjectDataSource
◦ AccessDataSource
◦ XmlDataSource
◦ SiteMapDataSource
14. Data Source Binding in the Page
Life Cycle
1. Page Initialization and Page Load
2. Control events handling
3. Data source controls perform
updates (insert, update, delete)
4. Page PreRender
5. Data source controls performs
queries and fill controls (Selecting
and Selected Events fired)
6. Page is rendered then Disposed
19. N-Tier Architecture
Database code MUST NOT be directly in
the client, but encapsulated in classes.
Easier maintenance and extension
Appropriate for all types of applications
(small/medium/large and desktop/Web)
applications.
Implementation:
◦ Create the front-end user interface (Windows
Forms or Web Forms)
◦ Create the business rule component class
library
◦ Create a data layer component class library to
20. N-tier layers
User Interface
Business Access Layer (BAL) to wrap
the business rules and logic (if
needed)
Business Object Layer (BOL) to wraps
each database table or business
object
Data Access Layer (DAL) to perform
database operations
21.
22.
23. ObjectDataSource Controls
Use ObjectDataSource is used with
the DAL classes
Instead of SQLDataSource Controls
◦ Maintenance nightmare
◦ Lack of flexibility
26. Lab #4
Bind Categories in regiter.aspx to
Categories table through
SQLdatasource control
Add a new Customer through the
registeration Page by using a data
component
Create Page to see and edit all
Customer Data using DetailsView or
FormView
27. Bonus
Add a page to see, edit , insert new
books and upload images
28. REFERENCES
[1] Beginning ASP.NET 4 In C# 2010, Matthew
Macdonald, Apress
[2] Web Application Architecture
Principles, Protocols And Practices, Leon Shklar
And Richard Rosen, Wiley
[3] Professional AS P.NE T 4 In C# And VB, Bill
Evjen, Scott Hanselman And Devin Rader, Wiley
[4] Pro ASP.NET In C# 2010, Fourth
Edition,matthew Macdonald, Adam Freeman, And
Mario Szpuszta, Apress