Asp. NET common data-bound control pros and cons summary

Source: Internet
Author: User

The purpose of this article is to make an overview of ASP. NET data-bound control, mainly analyze the advantages and disadvantages of various data-bound controls, so as to choose the appropriate control for data binding in the actual development to improve the development efficiency.

Because most of these data-bound controls are already encapsulated well, a little basic friends can easily get started, so this article does not involve the use of specific controls, only to analyze their merits and demerits, but in the next article, I will mainly talk about the ListBox, GridView, Repeater these three data-bound controls "efficient paging", the ListBox and the GridView built-in pagination, but its efficiency is too low, a small amount of data can be, a lot of data is not available at all, the Repeater control itself does not provide paging, But in the actual development may also be useful to the paging, so will also give you a talk about, repeater of pagination.

OK, now get to the point, start with the more commonly used controls.

First, the GridView control

Main Features: Support delete, change, sorting, paging, appearance settings, custom display data

Cons: Affects program performance and does not support insert operations

This control can display, edit, and delete data from a variety of different data sources, such as databases, XML files, and collections, in tabular form (table labels). The GridView control is very powerful and, if needed, can be used without writing any code, dragging with VS 2008 and setting properties from the Properties panel, as well as functions such as paging, sorting, and appearance settings. Although the functionality is complete, program performance is affected and it is best not to use the control too much on the page. Of course, if you need to display a variety of data in a custom format, the GridView control also provides template functionality for editing formatting, but does not support data insertion.

Icon:

Second, the ListView control

Main Features: Provide add, delete, change, sort, paging and other functions, can also support user-defined templates

Disadvantage: Affect program performance, big data paging efficiency is low

The ListView control displays data in a template format written by the programmer. Like the DataList and Repeater controls, the ListView control also applies to any data that has a repeating structure. However, the ListView control provides data manipulation features such as user editing, inserting, and deleting data, as well as the ability to sort and page through the data, just set directly in VS 2008 without writing code, which is very similar to the GridView control. It can be said that the ListView has both an open template for the Repeater control and the edit attribute of the GridView control. The ListView control is a new control in ASP. NET 3.5, and its paging functionality needs to be implemented with the DataPager control. The ListView control is a new control in ASP. NET 3.5, and its paging functionality needs to be implemented with the DataPager control. But for a lot of data, the efficiency of paging is very low, so in the next section, I will lead you to make an efficient paging. In general, the ListView is by far the most versatile and best-used data-bound control.

Third, Repeater control

Key benefits: The control is a complete, developmental control that allows you to freely display the user-defined display

Cons: pagination, sorting, editing are not supported, only duplicate template content is provided

The Repeater control is a data-bound container control that generates a list of the individual subkeys that can be displayed entirely by the programmer itself. When the control's page runs, the control repeats the data display format defined in the template based on the number of rows in the data source, and the programmer can fully grasp the display layout of the data, such as using DIV elements, UL elements, and so on. But the drawback is that the control does not support such as sorting, paging, editing and other functions, only support the duplicate template content functionality, but in the actual development may be useful to paging and other functions, so in the next section, I will focus on the repeater of the pagination.

Iv. DataList controls

The main advantages: You can display data in a custom format, more flexible

Cons: Paging not supported, edit insert

The control can display the fields of various data sources in a custom format, the format of which the data is displayed is defined in the template that is created, and templates can be created for items, alternating items, selected items, and edit items. The DataList control can also customize the overall appearance using the title, footnote, and delimiter templates, and you can display multiple rows of data in a row. Although the DataList control has a lot of flexibility, it does not natively support data paging, and programmers need to write their own method to complete the paging function. For display of data only, edit, insert, delete are not supported.

V. DetailsView controls

Key Benefits: Display a single piece of data in tabular format, support sorting, inserting, deleting, modifying, paging

Cons: Sorting is not supported

The DetailsView control displays only a single record of the data source at a time in tabular form (table label), and each row (TR label) under the Table label represents a field in the record. This control also supports editing, inserting, and deleting data, and it is easy to set the paging functionality, but the DetailsView control itself does not support data ordering.

Six, the FormView control

Main advantages: Display single data, pagination, add, delete, change, can be customized template display

Cons: Sorting is not supported

The FormView control is functionally similar to the DetailsView control, and the FormView control can display only a single record in the data source. Unlike the DetailsView control, the DetailsView control takes a table layout (table label), and each field of the record is displayed as a row. While the FormView control does not have a preset layout for displaying records, programmers need to create their own child item templates, write various controls to display the fields in the record, and other HTML tags for the layout. As with DetailsView controls, the FormView control can easily enable paging functionality. If you only display a single record, the FormView control is a more recommended method because you can customize the format of the data display while you are efficiently developing it.

VII. DROPDOWNLIST controls

Main advantages: Multi-level linkage

Cons: Display a field as much as possible

DropDownList control is generally used for multi-level linkage, such as the linkage of provinces and cities, the main point here is to set the field for DropDownList to display fields and values to display the field is:

After binding, the results are as follows:

To this point, we have analyzed the merits and demerits of the data-bound control of ASP. We only have a deep understanding of the characteristics of each control, we can better use the appropriate control in the appropriate situation, and better promote the development of the program. Of course, in the actual development process, we will not use these controls, after the Microsoft package to generate too much additional information, increase the pressure on the server. However, we have summed up these things and hope to help you. Also hope that we have a lot of advice!

Asp. NET common data-bound control pros and cons summary

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.