Introduction A data source control interacts with the data-bound controls and hides the complex data binding processes. It supports execution of operations like insert, delete, sort and update. Based on the type of data, these controls are divided into two categories: a. Hierarchical data source controls . b. Table-based data source controls. The data source controls used for hierarchical data are: 1. XMLDataSource-allows binding to XML files and strings with or without schema information 2. SiteMapDataSource-allows binding to a provider that supplies site map information The data source controls used for tabular data are: 1. AccessDataSource 2. SQLDataSource 3. ObjectDataSource 4. LinqdataSource
AccessDataSource control The AccessDataSource control enables you to retrieve data from a Microsoft Access database (.mdb file). The Most Common Use of this control is to link the following Controls to a database: GridView control FormView control DetailsView control DataList control etc 1. Create a Web Application and save it as AccessDataSource. Using the Control 2. Drag and drop an AccessDataSource control on the design view of the Default.aspx page. 3. Click the Smart Tag and select the Configure Data Source option.
4. Click the Browse button in the wizard, select Microsoft Access Database. Data Bound Controls Introduction Data-bound Web server controls are controls that can be bound to a data source control to make it easy to display and modify data in your Web application. Data-bound Web server controls are composite controls that combine other ASP.NET Web controls, such as Label and Textbox controls, into a single layout. These Controls enable you to customize the layout of the control using various templates provided in the control. Some Web-Server Controls are: FormView Control ListView Control DataList Control DetailsView Control Repeater Control
FormView Control The FormView control gives you the ability to work with a single record from a data source. The control specifies a pre-defined layout for displaying the record. Also, you create a template containing controls to display individual fields from the record. The template contains the formatting, controls, and binding expressions used to create the form. The FormView control is typically used for updating and inserting new records.
DetailsView Control Introduction DetailsView displays a single record from a data source. It provide a way to show, edit, update, insert or delete a single record at a time. Typically this control used for updating and inserting records. DetailsView updating, inserting and deleting records task depend on the data source control capabilities. DetailsView does not support sorting. This control support paging. It create a user interface for paging if we set the AllowPaging property value to true.
Contd .NET developers can populate a detailsview with data using many data source control such as SqlDataSource, LinqDataSource, ObjectDataSource control.
TemplateField enables developer to specify templates that contain markup and controls to customize the layout of a row in detailsview. we can use ItemTemplate, InsertItemTemplate and EditItemTemplate to more customize the data insert and edit interface.
ListView Control Introduction The ASP.NET ListView control enables you to bind to data items that are returned from a data source and display them. You can display data in pages. You can display items individually, or you can group them.
The ListView control displays data in a format that you define by using templates and styles. It is useful for data in any repeating structure, similar to the DataList and Repeater controls. However, unlike those controls, with the ListView control you can enable users to edit, insert, and delete data, and to sort and page data, all without code. Using The Control Repeater Control Repeater Control The Repeater control is a container control that allows you to create custom lists out of any data that is available to the page. The Repeater control does not have a built-in rendering of its own, which means that you must provide the layout for the Repeater control by creating templates. When the page runs, the Repeater control loops through the records in the data source and renders an item for each record. The following list describes the Repeater templates that are supported by the Repeater control:
ItemTemplate: Contains the HTML elements and controls to render once for each data item in the data source. AlternatingItemTemplate: This template is used to create a different look for the alternating items, such as a different background color than the color that is specified in the ItemTemplate. HeaderTemplate and FooterTemplate: Contains the text and controls to render at the beginning and end of the list, respectively. SeparatorTemplate: Contains the elements to render between each item. <asp:Repeater ID="Repeater1" runat="server" DataSourceID="AccessDataSource1"> <HeaderTemplate> <table><tr> <th>ID</th> <th> Name</th> <th>Address</th> <th>Age</th> </tr> </HeaderTemplate>
</asp:Repeater> DataList Control Introduction The DataList control is a combination of the DataGrid and the Repeater controls.
It displays data in a format that you can define using templates and styles.
The DataList control is useful for data in any repeating structure, such as a table. Contd Template property and Description: Item Template: Contains the HTML elements and controls to render once for each row in the data source.
AlternatingItem Template: Contains the HTML elements and controls to render once for every other row in the data source. Typically, you use this template to create a different look for the alternating rows, such as a different background color than the color that is specified in the ItemTemplate property.
SelectedItem Template: Contains the elements to render when the user selects an item in the DataList control. Typically, you use this template to visually distinguish the selected row with a different background or font color. You can also expand the item by displaying additional fields from the data source.
Contd EditItem Template: Specifies the layout of an item when it is in edit mode. This template typically contains editing controls, such as TextBoxcontrols.
HeaderTemplate and FooterTemplate: Contains the text and controls to render at the beginning and end of the list, respectively.
SeparatorTemplate: Contains the elements to render between each item. A typical example might be a line (using an HR element).