The gridview control is used to display data in a table. By using the gridview control, you can display, edit, delete, sort, and read table data in a variety of different data sources (including databases, XML files, and public data business objects. Displaying table data is a periodic task in software development. ASP. NET provides many tools to display table data in a grid, such as the gridview control. By using the gridview control, you can display, edit, and delete data in a variety of different data sources, such as databases, XML files, and business objects that expose data. You can use the gridview to automatically bind and display data through the data source control. Select, sort, pagination, edit, and delete data using the data source control. In addition, you can customize the appearance and behavior of the gridview control by specifying the Custom column and style. Use a template to create a Custom User Interface (UI) element. By handling the event Code Add to the gridview control function. 1.1 using the gridview Control for data binding the gridview control provides two options for Data Binding: using the performanceid attribute for data binding, this option allows you to bind the gridview control to the data source control. We recommend that you use this method because it allows the gridview control to take advantage of the functions of the data source control and provides built-in sorting, paging, and update functions. Use the datasource property to bind data. This option enables you to bind to various objects including ADO. Net datasets and data readers. This method requires coding for all additional functions (such as sorting, paging, and update. When the performanceid attribute is bound to the data source, the gridview control supports two-way data binding. In addition to displaying the returned data, the control can also automatically update and delete bound data. 1.2 you can set the data display format in the gridview control to specify the layout, color, Font, and alignment of rows in the gridview control. You can specify the display of text and data contained in a row. In addition, you can specify whether to display data rows as projects, alternate items, and selected items or edit mode items. The gridview control also allows you to specify the column format. 1.3 Use the gridview control to edit and delete data. By default, the gridview control displays data in read-only mode. However, this control also supports an editing mode in which the control displays rows containing editable controls (such as textbox or checkbox controls. You can also configure the gridview control to display a delete button. You can click this button to delete the corresponding records in the data source. The gridview control can automatically edit and delete the data sources associated with it, so that you can enable editing without coding. Alternatively, you can control the process of editing and deleting data programmatically (for example, when the gridview control is bound to a read-only data source control ). You can use a template to customize the input controls used when a row is in editing mode. 1.4 The gridview sorting function supports sorting by a single column without any programming. By using sorting events and providing sorting expressions, You can further customize the sorting function of the gridview control. 1.5 The pagination function of the gridview control provides a simple paging function. You can use the pagertemplate attribute of the gridview control to customize the pagination function of the gridview control. Applicable scenarios the gridview control is generally applicable to displaying two-dimensional relational data of rules in the form of tables. For example, it is used to display the list of all users under the site. 2. datalist control datalist Web Server Control displays database row information in a custom format. The format of the displayed data is defined in the created template. You can create templates for items, alternate items, selected items, and edit items. The header, footer, and separator templates are also used to customize the overall appearance of datalist. By adding a web server control to a template, you can connect the list items to the Code, which allows you to switch between display, selection, and editing modes. Different from the gridview, datalist must use a custom template to display data items. Compared with the gridview, datalist does not support sorting and paging. Use Cases: datalist is generally applicable to displaying data with a "single column, multiple rows" relationship. For example, it is used to display the product list. Each listitem displays the information of a product. You can define your own format for listitem. 3. The repeater Web Server Control is a container control that allows you to create a custom list from any available data on the page. The Repeater control does not have a built-in rendering function, which means that you must provide a layout for the Repeater control by creating a template. When this page is running, the repeater control uses records from the data source in sequence and presents an item for each record. The Repeater control is the shortest compared with the preceding two controls. repeater is generally used for read-only data and does not have the edit, sort, and paging functions for the list displayed by data. The applicable scenario features are very thin. It uses a set of records returned by the data source to present a read-only list. 4. The detailsview control displays a table record at a time and provides the ability to read multiple records and insert, update, and delete records. The detailsview control is usually used in the master/details solution. In this solution, the selected records in the master control (such as the gridview Control) determine the records displayed by the detailsview control. 5. The formview control is similar to the detailsview control. It presents a record in the data source at a time and provides the ability to read multiple records and insert, update, and delete records. However, the difference between the formview control and the detailsview control is that the detailsview control uses a table-based layout in which each field of the data record is displayed as a row in the control. The formview control does not specify the predefined layout for displaying records. In fact, you will create a template containing the control to display each field in the record. This template contains the format, controls, and binding expressions used to set the form layout.
The gridview control is used to display data in a table. By using the gridview control, you can display, edit, delete, sort, and read table data in a variety of different data sources (including databases, XML files, and public data business objects.
Displaying table data is a periodic task in software development. ASP. NET provides many tools to display table data in a grid, such as the gridview control. By using the gridview control, you can display, edit, and delete data in a variety of different data sources, such as databases, XML files, and business objects that expose data.
You can use the gridview to complete the following operations:
You can use the data source control to automatically bind and display data.
Select, sort, pagination, edit, and delete data using the data source control.
In addition, you can customize the appearance and behavior of the gridview control in the following ways:
Specify custom columns and styles.
Use a template to create a Custom User Interface (UI) element.
Add your code to the gridview control by processing the event.
1.1 Use the gridview Control for Data Binding
The gridview control provides two options for binding to data:
Use the performanceid property to bind data. This option allows you to bind the gridview control to the data source control. We recommend that you use this method because it allows the gridview control to take advantage of the functions of the data source control and provides built-in sorting, paging, and update functions.
Use the datasource property to bind data. This option enables you to bind to various objects including ADO. Net datasets and data readers. This method requires coding for all additional functions (such as sorting, paging, and update.
When the performanceid attribute is bound to the data source, the gridview control supports two-way data binding. In addition to displaying the returned data, the control can also automatically update and delete bound data.
1.2 set the data display format in the gridview Control
You can specify the layout, color, Font, and alignment of rows in the gridview control. You can specify the display of text and data contained in a row. In addition, you can specify whether to display data rows as projects, alternate items, and selected items or edit mode items. The gridview control also allows you to specify the column format.
1.3 Use the gridview control to edit and delete data
By default, the gridview control displays data in read-only mode. However, this control also supports an editing mode in which the control displays rows containing editable controls (such as textbox or checkbox controls. You can also configure the gridview control to display a delete button. You can click this button to delete the corresponding records in the data source.
The gridview control can automatically edit and delete the data sources associated with it, so that you can enable editing without coding. Alternatively, you can control the process of editing and deleting data programmatically (for example, when the gridview control is bound to a read-only data source control ).
You can use a template to customize the input controls used when a row is in editing mode.
1.4 gridview sorting
The gridview control supports sorting by a single column without any programming. By using sorting events and providing sorting expressions, You can further customize the sorting function of the gridview control.
1.5 gridview paging Function
The gridview control provides a simple paging function. You can use the pagertemplate attribute of the gridview control to customize the pagination function of the gridview control.
Applicable scenarios
The gridview control is generally used to display two-dimensional relational data of rules in the form of tables. For example, it is used to display the list of all users under the site.
2. datalist Control
The datalist Web Server Control displays information about database rows in a custom format. The format of the displayed data is defined in the created template. You can create templates for items, alternate items, selected items, and edit items. The header, footer, and separator templates are also used to customize the overall appearance of datalist. By adding a web server control to a template, you can connect the list items to the Code, which allows you to switch between display, selection, and editing modes.
Different from the gridview, datalist must use a custom template to display data items. Compared with the gridview, datalist does not support sorting and paging.
Applicable scenarios
Datalist is generally used to display data in the "single column, multiple rows" relationship. For example, it is used to display the product list. Each listitem displays the information of a product. You can define your own format for listitem.
3. Repeater control
The repeater Web Server Control is a container control that allows you to create a custom list from any available data on the page. The Repeater control does not have a built-in rendering function, which means that you must provide a layout for the Repeater control by creating a template. When this page is running, the repeater control uses records from the data source in sequence and presents an item for each record.
The Repeater control is the shortest compared with the preceding two controls. repeater is generally used for read-only data and does not have the edit, sort, and paging functions for the list displayed by data.
Applicable scenarios
The function is very thin. It uses a set of records returned by the data source to present a read-only list.
4. detailsview Control
The detailsview control displays a record in the form of a table at a time, and provides the ability to read multiple records and insert, update, and delete records. The detailsview control is usually used in the master/details solution. In this solution, the selected records in the master control (such as the gridview Control) determine the records displayed by the detailsview control.
5. formview Control
The formview control is similar to the detailsview control. It presents one record in the data source at a time and provides the ability to read multiple records and insert, update, and delete records. However, the difference between the formview control and the detailsview control is that the detailsview control uses a table-based layout in which each field of the data record is displayed as a row in the control. The formview control does not specify the predefined layout for displaying records. In fact, you will create a template containing the control to display each field in the record. This template contains the format, controls, and binding expressions used to set the form layout.