To bind a control using the asp+ list (top)

Source: Internet
Author: User
Introduction to Asp+| Controls

The Repeater, DataList, and DataGrid controls form system.web in the asp+ page frame.
Ui. WebControls a set of related Web controls within a namespace. These controls bind the HTML display
The contents of a set list or data source. Therefore, collectively they are referred to as "list-bound controls."

With other Web in the frame

controls, which provide a consistent programming model and encapsulate a browser-independent
Represents the logic. These features enable developers to program against the object model without having to master the
HTML related to those inconsistent and complex technical knowledge.

These three controls can be in a variety of layouts (including lists, columns/newspaper columns, and flow layouts)
(HTML stream) to represent the content of the data source associated with it. In addition, they allow you to finish creating
All different or fully customizable layouts. In addition to encapsulating the presentation logic, there is also a provision for handling
The ability to send data, perform state management, and raise events. Finally, they also have a choice,
Standard operations such as editing, paging, and sorting provide different levels of support. These controls can be simplified
Several common WEB application scenarios, including reports, shopping carts, product lists, queries
Results and navigation menus.

The following sections further explain these controls and how to use them in your WEB application
them, and how to select controls.

How does a list-bound control work?

This section is the background material for the remainder of this article. Summarizes the working parties for these list-bound controls
, their common characteristics and some related concepts.

DataSource Property
Each control has a DataSource property of type System.Collections.
ICollection. In the simplest terms, a data source is a list or collection of objects of the same kind.

There are several objects in this framework that provide a ICollection implementation. This collection includes
System.Data.DataView (which is typically used to access relational databases and XML data), a
Like ICollection implementations (such as ArrayList and Hashtable) and arrays.

Unlike traditional data-bound controls, which typically require an ADO recordset, in addition to implementing
ICollection interfaces, these list-bound controls do not impose any other to their data sources
Please. By design, a significant increase in the types and data available as valid DataSource property values
Structure, which enables maximum simplicity and flexibility for your application code.

Project Collection

Each list-bound control contains a project collection. Control by enumerating the objects that are currently
Data source to place into its project collection. Create a single item for each object in the enumeration and use it for the table
Shows the object. These items are also part of the control hierarchy contained in a list-bound control
Part

The following table lists the project types associated with data from the data source.

Default project type created by project
AlternatingItem for projects with odd subscript in the project collection
SelectedItem is created for the selected project, whether or not it is an alternative project
EditItem is created for an item in edit mode (regardless of whether it is selected or is an alternative item)


Control to create the following items that will be used in the presentation. However, they are not associated with the data source
associated with the data.

Headers are used to represent header information
Footnotes are used to denote footnote information
Delimiters are used to represent the content between each of the items shown in Figure 1 and apply only to Repeater and DataList
The page break is used to represent the paging UI associated with the DataGrid control



Data binding and creation of projects

List-bound controls follow the explicit data-binding model that is implemented throughout the asp+ framework. This
means that the control needs to be tied to its data source only when its DataBind method is invoked.

When calling DataBind

method, the list control enumerates its data source, creates the project, and extracts it from its data source
Takes a value to initialize it. If state management is enabled, the control will also save the required full
Information in order to re-create its project during the return processing of the page without having to reset the data
Source.

The explicit data-binding model enables your application code to accurately determine in the process sequence
When and where to need a data source. This functionality makes access to the database server less and more efficient,
These accesses are typically the most resource-intensive operations of a WEB application.

The general rule is that you must call DataBind whenever you need to re-create the project. In most
In several cases, you will invoke DataBind when your page is first requested to create the initial project collection.
During subsequent execution of this page, you will need the various events that caused the project collection to be changed
This method is called in a handler. When the query used to create the initial data source is modified, it is possible
This happens. When the state of a project changes, such as from read-only mode to edit mode, you can also
This can happen.

Style

By using style properties on the object model, you can define all DataList and DataGrid
Control and the format and appearance of the items it contains. These properties allow you to customize the font, color, border
and other cosmetic factors. The style properties of the control itself, such as the foreground color, background color, font, and border
Style) will affect the representation of the entire control.

In addition, each control contains a large number of style attributes that match the type of project that you create.
such as ItemStyle, AlternatingItemStyle and HeaderStyle. The DataGrid provides
The third-level style properties that affect all cells in a particular column. Control contained in the
Each column can have its own headerstyle, FooterStyle and ItemStyle.

Template

The style controls the format display, while the template defines the contents and representations for each item. You can add
The template is treated as an HTML code fragment, which defines the control hierarchy that is used to represent the project.

The Repeater and DataList controls are driven by templates that you specify, providing a variety of available
Set of template properties, such as ItemTemplate, AlternatingItemTemplate, and header
Template. Similar to styles, each template corresponds to a specific type of item.

The DataGrid control is not templated. However, the Template in the control's Column collection
Columns makes the use of templates in the DataGrid possible. Each single in the TemplateColumn
Wenge can contain a template, which is very much the item in the Repeater or DataList control
is similar. This also makes customization representations in the DataGrid possible.

Data binding in a template

The template defines the control hierarchy that is contained in the project. By using a data-binding expression, this
Control properties in a hierarchy can be bound to the data properties associated with this project.

An item that is the logical parent of a template is called a "container" in a data-binding expression. Every
A container has a property called DataItem that refers to its associated data. Results
Yes, most typical data-binding expressions in the template bind control properties to Container.
On a property of DataItem. This binding is further illustrated in the examples that are described in the following sections.

Repeater Control

As mentioned earlier, the Repeater control is completely template-driven, allowing you to create a fully configurable
The representation and layout of the system. The following figure illustrates this feature.



Excerpt from repeater1.aspx:

〈%@ Page language= "C #" s



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.