You use DataBound controls to generate your application’s user interface for working with data. The dataBound controls can be used to display and edit database data, XML data, or just about any other type of data you can imagine. There are three main types of DataBound controls: list controls, tabular DataBound controls, and hierarchical DataBound controls.
Working with List Controls
List controls are used to display simple option lists. The ASP.NET 3.5 Framework includes the following five List controls:
BulletedList— displays a bulleted list of items. Each item can be displayed as text, a link button, or a hyperlink.
CheckBoxList—displays a list of check boxes. Multiple check boxes in the list can be selected.
DropDownList—displays a drop-down list. Only one item in the drop-down list can be selected.
ListBox—displays a list box. You can configure this control so that only one item in the list can be selected or multiple items can be selected.
RadioButtonList—displays a list of radio buttons. Only one radio button can be selected.
Working with Tabular DataBound Controls
The tabular DataBound controls are the main set of controls that you use when working with database data. These controls enable you to display and, in some cases, modify data retrieved from a database or other type of data source.
There are six tabular DataBound controls. These controls can be divided into two types: Those that display multiple data items at a time and those that display a single data item at a time.
First, you can use any of the following controls to display a set of data items:
GridView—Displays a set of data items in an HTML table. For example, you can use the GridView control to display all the records contained in the Movies database table. This control enables you to display, sort, page, select, and edit data.
DataList—Displays a set of data items in an HTML table. Unlike the GridView control, more than one data item can be displayed in a single row.
Repeater—Displays a set of data items using a template. Unlike the GridView and DataList controls, a Repeater control does not automatically render an HTML table.
ListView—Displays a set of data items using a template. Unlike the Repeater control, the ListView control supports sorting, paging, and editing database data. You can use either of the following two controls to display a single data item at a time:
DetailsView—displays a single data item in an HTML table. For example, you can use the DetailsView control to display a single record from the Movies database table. This control enables you to display, page, edit, and add data.
FormView—Uses a template to display a single data item. Unlike the DetailsView, a FormView enables you to layout a form by using templates.
Working with Hierarchical DataBound Controls
A hierarchical DataBound control can be used to display nested data items. For example, you can use hierarchical DataBound controls to display the folder and page structure of your website, the contents of an XML file, or a set of master/detail database records. The ASP.NET 3.5 Framework includes two hierarchical DataBound controls:
Menu—Displays data items in a static or dynamic menu.
TreeView—Displays data items in a tree.
Using Data Source control
You bind a DataBound control to a DataSource control. A DataSource control is used to represent a particular type of data. The ASP.NET 3.5 Framework includes the following six DataSource controls:
SqlDataSource—Represents data retrieved from a SQL relational database, including Microsoft SQL server, Oracle, or DB2.
LinqDataSource—Represents a LINQ to SQL query.
AccessDataSource—Represents data retrieved from a Microsoft Access database.
ObjectDataSource—Represents data retrieved from a business object.
XmlDataSource—Represents data retrieved from an XML document.
siteMapDataSource—Represents data retrieved from a Site Map Provider. A Site Map Provider represents the page and folder structure of a website.
The ASP.NET Framework contains two basic types of DataSource controls. The SqlDataSource, AccessDataSource, LinqDataSource, and ObjectDataSource controls all derive from the base DataSourceControl class. These controls can be used to represent tabular data. The XmlDataSource and SiteMapDataSource controls, on the other hand, derive from the base HierarchicalDataSourceControl control. These two controls can be used to represent both tabular and hierarchical data.
Programmatic data binding
Every DataBound control has a DataSource property and a DataBind() method. By using this property and method, you can programmatically associate a DataBound control with a data source.
Understanding Templates and DataBinding Expressions
Every DataBound control included in the ASP.NET 3.5 Framework supports templates with the sole exception of the TreeView control. You can use a template to format the layout and appearance of each of the data items that a DataBound control displays
A DataBinding expression is a special type of expression that is not evaluated until runtime. You mark a Databinding expression in a page by wrapping the expression in opening brackets.
< %# Eval(“Title”) % >
< %# Eval(“Director”) % >
No comments:
Post a Comment