Displaying and Updating Data Here you will learn how to display, insert, update, and delete data using the popular data controls that you can use with ASP.NET. Besides working with the visual controls that are used to display and edit data in a web page, you will also learn how to work with the SqlDataSource control that acts as the bridge between the database and your ASPX pages.
ASP.NET offers two sets of data controls: the data-bound controls and the data source controls.
Data-Bound Controls are used to display and edit data, such as the GridView, Repeater, and ListView controls in the user interface. The data source controls are used to retrieve data from a data source, like a database or an XML file, and then offer this data to the data-bound controls.
THere are Seven different types of data-bound controls are present in Visual Studio. You can use them to display and edit data on your web pages. The GridView, DataList, ListView, and Repeater are all able to display multiple rows at the same time. As such they are often referred to as list controls. The DetailsView and the FormView are designed to show a single row at a time. The DataPager is a helper control used to provide paging capabilities to the ListView controls.
The GridView Control is a very flexible control that supports automatic paging (where rows are spread out over multiple “pages”), sorting, editing, deleting, and selecting. It generates its data like a spreadsheet with rows and columns.
The DataList control allows you to present data not only in rows as with the GridView, but in columns as well, It allows you to create a matrix-like presentation of data.
The Repeater gives you the greatest flexibility in terms of the HTML that you output to the browser because the control by itself does not add any HTML to the page output. As such, it is often used for HTML ordered or unordered lists (<ol> and <ul>).
The ListView was introduced in ASP.NET 3.5 and is a best-of-all-worlds combination of the GridView, the DataList, and the Repeater. It has undergone some changes in ASP.NET 4 and 4.5 that make it even easier to work with. The control supports editing, deleting, and paging of data, similar to the GridView. It supports multi-column and multi-row layouts like the DataList offers, and it allows you to completely control the markup generated by the control, just as the Repeater does. It also supports inserting and updating data like the DetailsView or FormView control.
In ASP.NET 4.5, the controls have been extended again with a new property: ItemType.
b)Single Item Controls
The DetailsView and FormView controls are somewhat similar in that both of them can display a single record at a time. The DetailsView uses a built-in tabular format to display the data, whereas the FormView uses templates to let you define the look and feel of your data.
The FormView control and a few of the Login controls you will see RenderOuterTable property. When you set this property to False (it defaults to True so you need to set it explicitly) the control doesn’t generate a wrapping HTML element. This in turn results in less code and cleaner HTML. Both controls enable you to define the templates for different situations, such as a read-only display of data, and inserting and updating of data.
Another useful control is the DataPager, which allows paging on other controls. For the time being, you can only use it to extend the ListView control, but that might change with future versions of the .NET Framework.
For the data-bound controls to display something useful, you need to assign them a data source. To bind this data source to the controls, two main methods are available: You can assign data to the control’s DataSource property, or you can use one of the separate data source controls.
Data Source Controls
The Data category of the Toolbox contains six different data source controls that you can use to bind data to your data-bound controls.
SqlDataSource Control – It provides access to any data source that has an ADO.NET data provider available,by default the control has access to the ODBC,OLE DB,SQL Server, ORACLE ,and SQL Server Compact providers.
LinqDataSource Control – It provides access to different types of LinqToSql objects using LINQ queries.
ObjectDataSource Control – It provides specialized data access to business objects or other classes that return data.
XmlDataSource Control – It provides specialized data access to XML documents, either physically on disk or in memory.
SiteMapDataSource Control – It provides specialized access to Sitemap data from a website that is stored by the sitemap provider.
AccessDataSource – It provides access to Access databases.
EntityDataSource – It provides specialized access to Entity Framework models.
How to Configure a Data Connection using SqlData Source Control