Title: ASP'NET 2'0
1ASP.NET 2.0
2DataBinding
- The term DataBinding refers to tying the value of
something to a source of values for that thing. - DataBinding may include a DataSource control, but
that need not be the case in every circumstance. - DataBinding may be one-way or two-way.
- One-way data-binding assigns source value to a
property of a control. Later changes in the
control will not change the source value. - Source ? bound-property of the control
- Two-way data-binding allows for the possibility
that later changes in the value of the control
will be reflected back in the data source
(consider a database update operation as an
example). - Source ? control
-
3DataBinding
Database, sitemap, or other data provider
These give 2-way DataBinding.
4DataBinding
Note we have commands for Selection (one-way
binding) and for Update, Delete, and Insert
(two-way binding)
Default mode is edit (2-way binding)
5DataSources and DataBinding
- The use of SqlDataSources with GridViews,
DetailsViews, and FormViews is a form of
DataBinding. - The use of SiteMapDataSources with Menus,
TreeViews, and so forth is DataBinding. - The DataBinding done so far is pretty vanilla.
It may be customized through the use of
parameters.
6Parameters in DataBinding
7Parameter Example
- If we have a GridView and would like to see a
DetailsView of the row selected in the GridView,
we need to tie the data source for the
DetailsView control to the selected item in the
GridView. - A parameter will help us in doing this.
8Parameter Example
GridView showing page of rows from database
DetailsView of the Selected row from GridView
DataSource is entire table of a database
DataSource must be just selected row of the table
9Configuring GridView DataSource
10Configuring GridView DataSource
Note all fields selected when we dragged table
from Server Explorer to the form.
DB Table name
Select the fields you want
Generated Select SQL statement
11Configuring GridView DataSource
We can Test the Query before we accept the
configuration.
Actual live data from table
12Configuring the DetailsView
Not the same DataSource as GridView we dont
want the whole table
13Configuring the DetailsView
Use same connection string because we want to use
the same database
14Configuring DetailsView
Same table and columns, but we want only the
selected row from GridView
15Configuring DetailsView
Select the Primary Key column (so it has a unique
value)
16Configuring DetailsView
Choose the operator (i.e., we want the ID
value in the Details View to be the ID of the
selected row in the GridView
Select Control because the selected row of the
GridView control is what we want to match
17Configuring DetailsView
SQL Where Clause being generated
Select the control we want to match
The parameter to match
18Final Where Clause
Value of Parameter
Click Add then OK
19Test It and Finish
20Viewing Resulting Web Page
21XmlDataSource
- An XML data source is a file that may be an
actual file in some folder or a file of XML
received from a web service such as an RSS feed. - Following is an example of an RSS feed reader
no-code program. - To illustrate this, the empty code-behind file
has been removed from the project. - See solution explorer
22RSS Feed Reader Example
23RSS Example Edit Templates
XPath finds a tag named pubDate in the XML
24Configuring the XmlDataSource
Finds an item tag inside a channel tag inside an
rss tag