Use the ASP. NET 2.0 formview control to control the display

Source: Internet
Author: User

The formview control of ASP. NET 2.0 is similar to the detailsview control, because it can easily display a single record of the backend data source. This article will discuss the syntax and application of this control.

[Chinese webmaster site]

 

Customized[Chinese webmaster site]

Although the two controls display one record at a time, the key difference between detailsview and formview is that formview uses user-defined templates, while detailsview uses row fields. The formview control does not have a pre-defined data layout. Instead, you create a template containing the control to display a single field in the record. The template contains the format, control, and binding expression used to create a form. [Chinese webmaster site]

You can control the display of data records in three forms: editing, viewing, and adding a new record. In addition, you can include and format the title and footer elements. You can also use any valid ASP. Net Control in each part of the formview control.

Chinaz.com

 

SyntaxChinaz.com

Declaring and using a formview control instance is very similar to declaring and using a detailsview control instance. The main difference between them is that, because no default settings are available, you must include the format and template of the displayed data in the formview control. List A displays part of the syntax for opening the formview element tag.

[Chinese webmaster site]

 

You may have noticed that many attributes correspond to HTML table elements, such as titles and borders. This shows that ASP. NET uses HTML tables to render the formview control.

Chinaz.com

 

You can view a more comprehensive list of formview controls online on the Microsoft website. The following table lists important attributes worth noting.

Chinaz.com

 

· Allowpaging: A boolean value indicating whether the user can return the records in the specified data source. If it is set to true, the default paging Number System (from 1 to the number of records) is displayed at the bottom of the displayed record ). Pagination links can be customized through various paging attributes.

Chinaz.com

 

· Datakeynames: The key field of the data source. Chinaz.com

· Performanceid: the ID of the element of the formview control data source. If SQL Server is used, it corresponds to the ID assigned to the sqldatasource element.

Chinaz.com

 

· Defaultmode: allows you to specify the default behavior of the control. That is to say, how is it first displayed during user access. Possible values include readonly, insert, and edit.

Chinaz.com

 

· Emptydatatext: Text displayed in case of NULL data values. [Chinese webmaster site]

When declaring the formview control, you must also format its content. Its data is displayed through the template. The formview control mainly uses five templates:

Chinaz.com

 

· Itemtemplate: it controls the display status when users view data.

[Chinese webmaster site]

 

· Edititemtemplate: it determines the format of the record and the display of data elements when the user edits the record. In this template, you will use other controls, such as textbox elements, to allow users to Edit values.

Chinaz.com

 

· Insertitemtemplate: similar to editing a record. This template allows you to add a new record field to the backend data source. Because a new value is input, users should be allowed to enter text or limit certain values according to data requirements. [Chinese webmaster site]

· Footertemplate: determines the content displayed in the footer of the formview control table, if any.

Chinaz.com

 

· Headertemplate: determines the content displayed in the table TITLE section of the formview control, if any.

Chinaz.com

 

These templates allow you to control the display and behavior of Data bound to a formview control. For example, Asp. net web forms connect to the standard northwind database, allowing users to view, edit, delete, and add new employee records through the name, last name, employment date, and home phone number fields.

Chinaz.com

 

It uses the textfield control to display the edited or added data and the displayed values only for viewing. Itemtemplate uses CSS to format the table, while inserttemplate uses HTML to format the table. The developer determines the method used.

[Chinese webmaster site]

 

Note: ASP. NET uses the button control to add, edit, delete, and save records. Chinaz.com

In the button control, the commandname value of new converts the record to the insert mode and loads the insertitemtemplate template, which allows the user to enter a new record value. You can use the commandname value of Edit to add a new button to the itemtemplate so that the formview control enters the editing mode. Chinaz.com

You can add a button with the delete commnadname value to the itemtemplate template to allow users to delete the current record from the data source. The update commnadname stores the data, while cancel terminates the operation. [Chinese webmaster site]

Developer Control

[Chinese webmaster site]

 

The usability of many new ASP. NET 2.0 features is surprising. Formview expands the simple functions of detailsview, allowing you to easily control the display content to be formatted as needed. This new control provides another option for your delivery solution.

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.