Updated April 10, 2023
Introduction to ASP.NET Web Controls
The ASP.NET page framework includes a number of built-in controls that are designed to provide a more structured programming model for the web. These controls provide many features like automatic state management, common approach to build the user interfaces for the web pages, simple access to object values without having to use request object, output is automatically customized based on the capabilities of the browser, ability to react to events in server side code to create applications that are better structured. These controls are objects placed in the ASP.NET pages that are processed by the ASP.NET runtime.
Different ASP.NET Web Controls
ASP.NET web controls are used to display the data in a web page.
Given below are the controls one by one:
1. GridView Control
GridView controls are used to display multiple records in webpage. It also enables you to add, update and delete a record in database without writing a single line of code. In GridView control x each column represents a filed while each row represents the record’s. To use GridView control DataSource control has to be attached to the GridView control.
The property DataSource of the GridView control binds the GridView control to the DataSource control and allows paging, sorting and database operations with the DataSource. ID, DataSource ID, DataKeyNames, AllowSorting, AllowPaging, Pagesize, AutoGenerateColumns, AutoGenerateEditButton, BackColor, BorderColor, BorderWidth, Caption, Width, Visible, SelectedIndex and Runat are some properties of the GridView control.
2. DetailsView Control
The DetailsView control is used to create an HTML table that displays the content of a single database record. There are three types of mode of DetailsView control namely Edit, Read and ReadOnly. Edit mode allows user to update the values of the record. Insert mode allows user to add a new record to the data source and ReadOnly mode used for display mode.
Attributes of DetailsView control are as follows:
- ID: It is used to specify the control identifier.
- Runat: It must be equal server.
- DataSourceID: It is the ID OF data source to bind the DetailsView control.
- DefaultMode: It is used to set the initial mode of control such as Edit, Insert and ReadOnly.
- DataKeyNames: It is a list of the column names that are primary key for the data source.
- AllowPaging: It creates paging numbers when it is equal to true.
Databinding, DataBound, ItemCommand, ItemCreated, ItemDeleted, ItemInserting, ItemUpdating, ItemUpdated, ModeChanging, ModeChanged, PageIndexChanging, PageIndexChanged are some events that are generated by DetailsView control.
3. FormView Control
FormView control is used to display a single record from database. It is similar to the DetailsView control, except it displays user defined templates instead of row fields. You can create your own template. It gives greater flexibility in controlling how the data is displayed. It is binding data source controls such as SqlDataSource and ObjectDataSource.
It has built in inserting capabilities, updating and deleting capabilities and paging capabilities. You can customize it through templates, themes and style. EditItem template controls the FormView control in edit mode. It includes textbox does each editable column in the data source. The textbox, text property uses binding expression which binds the data source field data to textbox. InsertItem template comptroller the FormView control in the insert mode. It is similar to the EditItem template.
4. ListView Control
The ListView control is very flexible web control that tender its contents based on the template you define. Unlike the repeater control, ListView adds higher level features such as selection and editing, which works in the same way in the GridView control. ListView control can replace all other data binding controls in asp.net. It makes data binding easier. It has included styling with CSS, flexible paging, inserting, deleting, sorting and updating features.
The most common reason for using ListView control is to create an unusual layout. ListView control includes buttons like cancel button which cancels edit or insert operation, select button which sets SelectedIndex property to the DisplayIndex property value for the item, delete button which delete the current record form the data source, edit button puts the ListView control in edit mode, update button updates the current record in the data source with the bound values and insert button inserts the bound values into data source.
5. DataPager Control
ListView control does not support paging directly, so the DataPager control serves an external control to provide paging features to ListView control. The advantage of separate control is that it gives more flexibility about what the pager looks like and where bit can be placed on the page. DataPager control can be linked with the data bound control by using the PagedControlID property. The numbers of items that are displayed for each page of data can be modified by changing the PageSize property. PagedControlID, PageSize, MaximumRow, StartRowIndex and TotalRowCount are the properties of DataPager control.
Conclusion
Here in this article, we have seen the various ASP.NET web controls with working, properties and attributes. To create a web page and handling the data on web, these control plays important roles. Based on the requirements we can make a use of these controls for data binding on web.
Recommended Articles
This is a guide to ASP.NET Web Controls. Here we discuss the introduction and different ASP.NET web controls respectively. You may also have a look at the following articles to learn more –