Control display with ASP.net 2.0 FormView control

Source: Internet
Author: User
Tags format contains include insert new features microsoft website
Asp.net| Control | control | The FormView control that displays ASP.net 2.0 is similar to the DetailsView control because it makes it easy to display a single record of a back-end data source. This article discusses the syntax and application of this control.

of the user

Although the two controls display one record at a time, the key difference between DetailsView and FormView is that the FormView utilizes user-defined templates, while DetailsView uses row fields. The FormView control does not have predefined data layouts; instead, you create a template that contains the controls to display a single field in the record. The template contains the formatting, controls, and binding expressions that are used to create the form.

You can control how data records are displayed in three different ways: edit, view, and add a new record. In addition, you can include and format headings and footer elements. You can also take advantage of any of the valid ASP.net controls in each part of the FormView control.

Grammar

Declaring and using a FormView control instance is very similar to declaring and using a DetailsView control instance. The main difference is that because there is no default setting to use, you must include the format and template for displaying the data in the FormView control. List A shows a portion of the syntax for opening the FormView element label.

You may have noticed that many attributes correspond to HTML table elements, such as headings and borders. This indicates that ASP.net uses an HTML table to render the FormView control.

You can view a more comprehensive list of FormView control properties online via the Microsoft website. The following table lists some of the important attributes that are worth paying attention to.

AllowPaging: A Boolean value that indicates whether a user can paging through records in a specified data source. If set to True, the default paging number system (number from 1 to record) is displayed at the bottom of the displayed record. Page links can be customized through various paging properties.
DataKeyNames: The key field of the data source.
DataSourceID: Used to migrate FormView control data source element IDs. If you use SQL Server, it corresponds to the ID assigned to the SqlDataSource element.
DefaultMode: Allows you to specify the default behavior of the control. That is, how it initially appears when the user accesses it. Possible values include: ReadOnly, insert, and edit.
Emptydatatext: The text to display when an empty data value is encountered.
When you declare a FormView control, you must also format its contents accordingly. Its data is displayed through a template. The FormView control mainly uses five templates:

ItemTemplate: It controls the display of data when viewed by the user.
EditItemTemplate: It determines how the format and data elements are displayed when the user edits the record. In this template, you will use other controls, such as the TextBox element, to allow the user to edit the value.
InsertItemTemplate: Similar to editing a record, this template controls the display of fields that allow users to add a new record to a backend data source. Because a new value is entered, the user should be allowed to enter text freely or limit certain values according to the requirements of the data.
FooterTemplate: Determines what the FormView Control Table footer section displays, if any.
HeaderTemplate: Determines what is displayed in the FormView Control Table header section, if any.
These templates allow you to control the display and behavior of data that is bound to a FormView control. For example, the ASP.net Web Form in List B is connected to a standard Northwind database, allowing users to view, edit, delete, and add new employee records by first name, last name, hire date, and home phone number field.

It uses the TextField control to display data that is edited or added, and values that are displayed only for lookup purposes. ItemTemplate uses CSS to format tables, and Inserttemplate uses HTML styles to format them, and it is up to the developer to decide which method to use.

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

In the button control, the CommandName value of new converts the record to insert mode and loads the InsertItemTemplate template, which allows the user to enter a new record value. You can add a new button to ItemTemplate using the CommandName value of edit to get the FormView control into edit mode.

You can add a button with the delete commnadname value to the ItemTemplate template, allowing the user to delete the current record from the data source. Update Commnadname saves the data, and cancel terminates the operation.

Developer Control

The ease of use of many ASP.net 2.0 new features is surprising. FormView expands on the simple features of DetailsView, allowing you to easily control what you want to format as needed. This new control provides another option for you to deliver the solution.


Related Article

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.