SlideShare a Scribd company logo
Chapter 10 Data Controls
Overview This chapter continues the broader topic of working with data in ASP.NET by focusing on how to work with ASP.NET’s powerful multivalue data controls.  It covers: Repeater  Control  DataList  Control FormView  Control  DetailsView  Control GridView  Control
Data Controls ASP.NET has five controls dedicated to the display of multiple values from a data source. These controls have several similarities: They all use template tags to separate the control data from its presentation.  That is, the control does not provide a user interface; rather, the user interface is customized by the developer via nested template elements.  They also all support data binding.  In fact, these controls can only display content via data binding.  These data controls vary in their flexibility, features, and speed.
DataList Control Displays rows of data as items in a list.  The presentation of the data can be customized via templates. Inline editing and deleting of data is also supported by this control.
Repeater Control Provides a list of data.  It is unique in that it provides complete flexibility in regard to the HTML presentation of the data.  However, because there is no default look, the developer must completely describe via templates how the data is to be rendered.
DetailsView Control Displays a single record of data at a time. It provides buttons for navigating from record to record.  As well, it supports the updating, insertion, or deletion of records.  It can be used in conjunction with the  GridView  control to provide a master-detail view of your data.
FormView Control Like the  DetailsView  control, the  FormView  control displays a single record of data at a time and supports the editing of the record.  Unlike the  DetailsView  control, the  FormView  control requires the use of templates to define the rendering of each item, so the developer can completely customize the appearance of the record.
GridView Control Displays data in a tabular (row-column) grid.  It provides the most features of the data controls.  It not only supports the editing and deleting of data, it also supports the sorting and paging of data.  Although it also uses templates to customize the appearance of the data, customizing the presentation requires more work than the  DataList .  There is a default look to the  GridView , so little work is required to displaying an entire table of data.
Understanding Templates The content and layout of list items in these controls are defined using  templates .  A template defines: the HTML elements,  the ASP.NET controls,  the layout of these controls,  the data to be displayed via data-binding expressions. Style formatting of a template, such as fonts and colors, is set via the unique style element for that template.
Templates The following table lists the available general templates: Name Description ItemTemplate Specifies the content and layout of items within a list. AlternatingItemTemplate Specifies the content and layout of alternating items. SeparatorTemplate Specifies what should appear between items (and alternating items). SelectedItemTemplate Specifies the content and layout of selected items. EditItemTemplate Specifies the content and layout of edited items. HeaderTemplate Specifies the content and layout of the header of the list. FooterTemplate Specifies the content and layout of the footer of the list
Templates
Data-Binding Expressions Within the various item templates (e.g., ItemTemplate, EditItemTemplate), you need to specify which data source fields you want to display.  ASP.NET provides a special declarative syntax for specifying data elements, generally referred to as  data-binding expressions .  The syntax for a data-binding expression is: E.g. <%# expression %> <%# Eval(&quot;LastName&quot;) %> <%# Eval(&quot;Price&quot;, &quot;{0:c}&quot;) %> composite formatting string
DataList Control The developer specifies which particular data items in the data source will be displayed in a repeating list.  This is done by using data-binding expressions within the ItemTemplate element. <asp:SqlDataSource ID=&quot;dsPubs&quot; runat=&quot;server&quot; ProviderName=&quot;System.Data.SqlClient&quot;  ConnectionString=&quot;<%$ ConnectionStrings:BookCatalog %>&quot; SelectCommand=&quot;Select PublisherId,PublisherName From Publishers&quot; /> <asp:DataList ID=&quot;dlstPub&quot; runat=&quot;server&quot; DataSourceID=&quot;dsPubs&quot;> <ItemTemplate> <%# Eval(&quot;PublisherName&quot;) %> </ItemTemplate> </asp:DataList>
DataList Control <asp:DataList ID=&quot;dlstPub&quot; runat=&quot;server&quot; DataSourceID=&quot;dsPubs&quot; CellPadding=&quot;5&quot; RepeatLayout=&quot;Table&quot;>   <HeaderTemplate> <h2>Publishers</h2> </HeaderTemplate>   <ItemTemplate> <%# Eval(&quot;PublisherName&quot;) %> </ItemTemplate>   <ItemStyle BackColor=&quot;AntiqueWhite&quot; ForeColor=&quot;Brown&quot;  Font-Size=&quot;Medium&quot; Width=&quot;150&quot; Height=&quot;25&quot; />   <AlternatingItemStyle BackColor=&quot;silver&quot; /> <SeparatorStyle BackColor=&quot;crimson&quot; Height=&quot;5&quot; /> <SeparatorTemplate></SeparatorTemplate> </asp:DataList>
Design-Time Support
Repeater Control Displays items in a repeating list.  Unlike the  DataList  control, the  Repeater  does not have an inherent look for example, it does not by default create a vertical list of data or a HTML  <table>  element.  Instead, you must provide the layout for the control via templates.  The  Repeater  only creates the HTML that you specify within the  ItemTemplate  element.  Although this usually means more work (by the developer) is required to display a simple list of data, it may be preferred by developers who prefer the complete control that the  Repeater  provides over the generated HTML.
Repeater <asp:Repeater ID=&quot;rptArtists&quot; runat=&quot;server&quot;  DataSourceID=&quot;dsBooks&quot;>   <HeaderTemplate> <h2 class=&quot;listHeading&quot;>Recent Books</h2> <dl> </HeaderTemplate>   <ItemTemplate> <dt><%# Eval(&quot;Title&quot;) %></dt> <dd class=&quot;bookImage&quot;> <asp:Image ID=&quot;imgBook&quot; runat=&quot;server&quot; ImageUrl='<%# String.Format(&quot;images/{0}.gif&quot;,Eval(&quot;ISBN&quot;)) %>'  AlternateText='<%# Eval(&quot;Title&quot;)%>' />  </dd> <dd class=&quot;publisher&quot;> <%# Eval(&quot;PublisherName&quot;) %>  (<%# Eval(&quot;YearPublished&quot;) %>) </dd> <dd> <%# Eval(&quot;BriefDescription&quot;) %>  </dd> </ItemTemplate>   <FooterTemplate> </dl> </FooterTemplate> </asp:Repeater>
FormView Control Displays a single record of data. Provides a built-in mechanism for navigating from record to record;  Supports the updating, insertion, and deletion of a record.
FormView Control <asp:FormView ID=&quot;frmvBooks&quot; runat=&quot;server&quot;  DataSourceID=&quot;dsBooks&quot;  CssClass=&quot;entireForm&quot;>   <HeaderTemplate> <h2>Book Details</h2> </HeaderTemplate>   <HeaderStyle CssClass=&quot;singleBookTitle&quot; />   <ItemTemplate> <div class=&quot;singleBook&quot;> ISBN: <br /> <asp:Label ID=&quot;labIsbn&quot; runat=&quot;server&quot; Text='<%# Eval(&quot;ISBN&quot;) %>' CssClass=&quot;dataValues&quot; /> <br /> Title:<br /> <asp:Label ID=&quot;labTitle&quot; runat=&quot;server&quot; Text='<%# Eval(&quot;Title&quot;) %>' CssClass=&quot;dataValues&quot; /> <br /> Publisher:<br /> <asp:Label ID=&quot;labPublisher&quot; runat=&quot;server&quot; Text='<%# Eval(&quot;PublisherName&quot;) %>'  CssClass=&quot;dataValues&quot; /> <br /> Year:<br /> <asp:Label ID=&quot;labDesc&quot; runat=&quot;server&quot; Text='<%# Eval(&quot;YearPublished&quot;) %>'  CssClass=&quot;dataValues&quot; /> <br /> Description:<br /> <asp:Label ID=&quot;Label1&quot; runat=&quot;server&quot; Text='<%# Eval(&quot;BriefDescription&quot;) %>' CssClass=&quot;dataValues&quot; /> <br />  </div> </ItemTemplate> </asp:FormView>
FormView Control Although the  FormView  control displays a single record of data, it can accept a data source containing multiple records. You can allow the user to move from record to record by setting the control’s  AllowPaging  property to true.
FormView The  FormView  control can also be used to provide the user with the ability to edit the data in a single record.
DetailsView Control Displays a single record of data at a time, provides a way to navigate from record to record, and supports the updating, insertion, or deletion of a record.  The  DetailsView  control differs from the  FormView  control in that it does not require the use of templates for defining the look of the control. it renders each field in the data source as a row in an HTML  <table>  element.
DetailsView Control <asp:DetailsView ID=&quot;detvBooks&quot; runat=&quot;server&quot;  DataSourceID=&quot;dsBooks&quot; />
DetailsView Control <asp:DetailsView ID=&quot;detvBooks&quot; runat=&quot;server&quot;  DataSourceID=&quot;dsBooks&quot; GridLines=&quot;None&quot; AllowPaging=&quot;true&quot; CellPadding=&quot;4&quot; ForeColor=&quot;#333333&quot; > <RowStyle VerticalAlign=&quot;Top&quot; BackColor=&quot;#EFF3FB&quot;/> <PagerStyle CssClass=&quot;detailsPagerStyle&quot; /> <FieldHeaderStyle BackColor=&quot;#DEE8F5&quot; Font-Bold=&quot;True&quot; /> <HeaderStyle CssClass=&quot;detailsHeaderStyle&quot;/> <AlternatingRowStyle BackColor=&quot;White&quot; /> </asp:DetailsView>
GridView Control Provides a way to display data in a tabular (row-column) grid.  You can use different field types to customize the visual display of the data within the grid.  Also like the  DetailsView  control, the  GridView  supports the paging of data as well as the automatic modification and saving of data when bound to a data source control.  The  GridView  also allows the user to sort or select data rows.
GridView Control <asp:GridView ID=&quot;grdSample&quot; runat=&quot;server&quot;  DataSourceID=&quot;dsBooks&quot; />
GridView Control <asp:GridView ID=&quot;grdSample&quot; runat=&quot;server&quot;  DataSourceID=&quot;dsBooks&quot; AutoGenerateColumns=&quot;False&quot; BackColor=&quot;White&quot; BorderColor=&quot;#DEDFDE&quot; BorderStyle=&quot;None&quot; BorderWidth=&quot;1px&quot;  CellPadding=&quot;4&quot; GridLines=&quot;Vertical&quot; ForeColor=&quot;Black&quot;>   <Columns> <asp:ImageField HeaderText=&quot;&quot; DataImageUrlField=&quot;Isbn&quot;  DataImageUrlFormatString=&quot;images/{0}.gif&quot; DataAlternateTextField=&quot;Title&quot;  DataAlternateTextFormatString=&quot;Book cover for {0}&quot; ReadOnly=&quot;True&quot; /> <asp:BoundField DataField=&quot;ISBN&quot; HeaderText=&quot;Isbn&quot;  ReadOnly=&quot;True&quot;/>  <asp:BoundField DataField=&quot;Title&quot; HeaderText=&quot;Title&quot;/> <asp:BoundField DataField=&quot;PublisherName&quot;  HeaderText=&quot;Publisher&quot;/> <asp:BoundField DataField=&quot;YearPublished&quot;  HeaderText=&quot;Year&quot;/>  </Columns>    <RowStyle CssClass=&quot;gridRow&quot; /> <HeaderStyle CssClass=&quot;gridHeader&quot; /> <AlternatingRowStyle CssClass=&quot;gridAlt&quot; /> </asp:GridView>
GridView Control CommandField ButtonField
Pagination The  GridView  control supports  pagination .  That is, rather than display all the records in the data source, pagination lets the control break its listing up into multiple, smaller pages displaying a subset of the complete data.  the user can then move to a specific page of data via pagination navigation buttons.  Pagination can be enabled for any  GridView ,  FormView , or  DetailsView  control by enabling its  AllowPaging  property.  The number of records to appear in each page can be set via the  PageSize  property.
Pagination How does it work? The answer depends on what type of data source control is being used. If a  SqlDataSource  control is being used, pagination effectively operates at the control level. If an  ObjectDataSource  control is being used, pagination must be implemented by the underlying object.
Pagination In a  GridView  with pagination using a  SqlDataSource  control,  all  the records that match the SELECT statement are read and stored into an internal  DataSet  every time the page is requested or posted back, regardless of whether pagination is enabled or not enabled.  If the SELECT statement returns 100000 records, but the  GridView  only displays 10 records per page, this is clearly an inefficient approach for a frequently requested page. In such a case, it would be better to refactor so that only the required data for the page is being requested by the database. This can be done at the DBMS level or at an  ObjectDataSource  level.
GridView Sorting The  GridView  control allows the user to change the visual sort order of the data displayed within the control.  When sorting is enabled for the  GridView  (by setting the  AllowSorting  property of the control to true), the user can change the sort order of the data by clicking the hyperlinked column header for that field.  Furthermore, the user can toggle between an ascending or descending sort order.
GridView Sorting <asp:GridView ID=&quot;grdSample&quot; runat=&quot;server&quot; DataSourceID=&quot;dsBooks&quot; AutoGenerateColumns=&quot;False&quot; CellPadding=&quot;4&quot;  GridLines=&quot;Vertical&quot; CssClass=&quot;bookList&quot; AllowSorting=&quot;true&quot;  >   <Columns> <asp:BoundField DataField=&quot;ISBN&quot; HeaderText=&quot;Isbn&quot;  SortExpression=&quot;Isbn&quot;  />  <asp:BoundField DataField=&quot;Title&quot; HeaderText=&quot;Title&quot;  SortExpression=&quot;Title&quot;  /> <asp:BoundField DataField=&quot;PublisherName&quot;  HeaderText=&quot;Publisher&quot;  SortExpression=&quot;PublisherName&quot;  /> <asp:BoundField DataField=&quot;YearPublished&quot;  HeaderText=&quot;Year&quot;  SortExpression=&quot;YearPublished&quot;  />  </Columns> … </asp:GridView>
Editing Data in GridView The  GridView  control supports the in-place editing of data within a row by the user.  In fact, you can add editing to a  GridView  control in almost  exactly  the same manner as with the  DetailsView  control.
Nested GridView Controls You can nest  GridView  controls in order to display data that has a one-to-many relationship.

More Related Content

PPTX
Database Connectivity in PHP
PPTX
Html links
PDF
Introduction to Bootstrap
PPT
Data controls ppt
PPT
MYSQL - PHP Database Connectivity
PPTX
HTML: Tables and Forms
PPTX
Database Connectivity in PHP
Html links
Introduction to Bootstrap
Data controls ppt
MYSQL - PHP Database Connectivity
HTML: Tables and Forms

What's hot (20)

PPTX
html-table
PDF
Basics of JavaScript
PPT
HTML Tags
PDF
Javascript basics
PPTX
C# Private assembly
PDF
jQuery for beginners
PPT
Asp.net control
PPT
C# Basics
PPTX
Structured Query Language (SQL)
PPT
Introduction to html
PDF
Bootstrap
PPTX
Html table
PDF
Introduction to HTML5
PPTX
PPT
Introduction to JavaScript (1).ppt
PPT
C# Exceptions Handling
PPT
ADO .Net
PPTX
Ajax ppt - 32 slides
PPT
1. Introduction to DBMS
PPT
Scripting languages
html-table
Basics of JavaScript
HTML Tags
Javascript basics
C# Private assembly
jQuery for beginners
Asp.net control
C# Basics
Structured Query Language (SQL)
Introduction to html
Bootstrap
Html table
Introduction to HTML5
Introduction to JavaScript (1).ppt
C# Exceptions Handling
ADO .Net
Ajax ppt - 32 slides
1. Introduction to DBMS
Scripting languages
Ad

Similar to ASP.NET 10 - Data Controls (20)

PPT
displaytag
PPT
Component and Event-Driven Architectures in PHP
PPT
10. XML in DBMS
PPT
Week7
PPT
Week7
PPS
PPT
ASP.NET 08 - Data Binding And Representation
PPT
Struts2
PDF
xml-150211140504-conversion-gate01 (1).pdf
PPTX
PPTX
Design Dream
PPT
ODP
Web Developement Workshop (Oct 2009) Slides
PPT
HTML
PPT
PPT
Web Development using HTML & CSS
PPT
PPT
Boston Computing Review - Ruby on Rails
PPTX
Markup Documents
PPTX
6th_sem_web_unit1_part2.pptxhshshshshshshsh
displaytag
Component and Event-Driven Architectures in PHP
10. XML in DBMS
Week7
Week7
ASP.NET 08 - Data Binding And Representation
Struts2
xml-150211140504-conversion-gate01 (1).pdf
Design Dream
Web Developement Workshop (Oct 2009) Slides
HTML
Web Development using HTML & CSS
Boston Computing Review - Ruby on Rails
Markup Documents
6th_sem_web_unit1_part2.pptxhshshshshshshsh
Ad

More from Randy Connolly (20)

PDF
Celebrating the Release of Computing Careers and Disciplines
PDF
Public Computing Intellectuals in the Age of AI Crisis
PDF
Why Computing Belongs Within the Social Sciences
PDF
Ten-Year Anniversary of our CIS Degree
PDF
Careers in Computing (2019 Edition)
PDF
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...
PDF
Where is the Internet? (2019 Edition)
PDF
Modern Web Development (2018)
PDF
Helping Prospective Students Understand the Computing Disciplines
PDF
Constructing a Web Development Textbook
PDF
Web Development for Managers
PDF
Disrupting the Discourse of the "Digital Disruption of _____"
PDF
17 Ways to Fail Your Courses
PDF
Red Fish Blue Fish: Reexamining Student Understanding of the Computing Discip...
PPTX
Constructing and revising a web development textbook
PDF
Computing is Not a Rock Band: Student Understanding of the Computing Disciplines
PDF
Citizenship: How do leaders in universities think about and experience citize...
PDF
Thinking About Technology
PDF
A longitudinal examination of SIGITE conference submission data
PDF
Web Security
Celebrating the Release of Computing Careers and Disciplines
Public Computing Intellectuals in the Age of AI Crisis
Why Computing Belongs Within the Social Sciences
Ten-Year Anniversary of our CIS Degree
Careers in Computing (2019 Edition)
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...
Where is the Internet? (2019 Edition)
Modern Web Development (2018)
Helping Prospective Students Understand the Computing Disciplines
Constructing a Web Development Textbook
Web Development for Managers
Disrupting the Discourse of the "Digital Disruption of _____"
17 Ways to Fail Your Courses
Red Fish Blue Fish: Reexamining Student Understanding of the Computing Discip...
Constructing and revising a web development textbook
Computing is Not a Rock Band: Student Understanding of the Computing Disciplines
Citizenship: How do leaders in universities think about and experience citize...
Thinking About Technology
A longitudinal examination of SIGITE conference submission data
Web Security

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
KodekX | Application Modernization Development
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Cloud computing and distributed systems.
PDF
Modernizing your data center with Dell and AMD
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Machine learning based COVID-19 study performance prediction
PDF
cuic standard and advanced reporting.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Big Data Technologies - Introduction.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
KodekX | Application Modernization Development
Digital-Transformation-Roadmap-for-Companies.pptx
Understanding_Digital_Forensics_Presentation.pptx
Cloud computing and distributed systems.
Modernizing your data center with Dell and AMD
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Machine learning based COVID-19 study performance prediction
cuic standard and advanced reporting.pdf

ASP.NET 10 - Data Controls

  • 1. Chapter 10 Data Controls
  • 2. Overview This chapter continues the broader topic of working with data in ASP.NET by focusing on how to work with ASP.NET’s powerful multivalue data controls. It covers: Repeater Control DataList Control FormView Control DetailsView Control GridView Control
  • 3. Data Controls ASP.NET has five controls dedicated to the display of multiple values from a data source. These controls have several similarities: They all use template tags to separate the control data from its presentation. That is, the control does not provide a user interface; rather, the user interface is customized by the developer via nested template elements. They also all support data binding. In fact, these controls can only display content via data binding. These data controls vary in their flexibility, features, and speed.
  • 4. DataList Control Displays rows of data as items in a list. The presentation of the data can be customized via templates. Inline editing and deleting of data is also supported by this control.
  • 5. Repeater Control Provides a list of data. It is unique in that it provides complete flexibility in regard to the HTML presentation of the data. However, because there is no default look, the developer must completely describe via templates how the data is to be rendered.
  • 6. DetailsView Control Displays a single record of data at a time. It provides buttons for navigating from record to record. As well, it supports the updating, insertion, or deletion of records. It can be used in conjunction with the GridView control to provide a master-detail view of your data.
  • 7. FormView Control Like the DetailsView control, the FormView control displays a single record of data at a time and supports the editing of the record. Unlike the DetailsView control, the FormView control requires the use of templates to define the rendering of each item, so the developer can completely customize the appearance of the record.
  • 8. GridView Control Displays data in a tabular (row-column) grid. It provides the most features of the data controls. It not only supports the editing and deleting of data, it also supports the sorting and paging of data. Although it also uses templates to customize the appearance of the data, customizing the presentation requires more work than the DataList . There is a default look to the GridView , so little work is required to displaying an entire table of data.
  • 9. Understanding Templates The content and layout of list items in these controls are defined using templates . A template defines: the HTML elements, the ASP.NET controls, the layout of these controls, the data to be displayed via data-binding expressions. Style formatting of a template, such as fonts and colors, is set via the unique style element for that template.
  • 10. Templates The following table lists the available general templates: Name Description ItemTemplate Specifies the content and layout of items within a list. AlternatingItemTemplate Specifies the content and layout of alternating items. SeparatorTemplate Specifies what should appear between items (and alternating items). SelectedItemTemplate Specifies the content and layout of selected items. EditItemTemplate Specifies the content and layout of edited items. HeaderTemplate Specifies the content and layout of the header of the list. FooterTemplate Specifies the content and layout of the footer of the list
  • 12. Data-Binding Expressions Within the various item templates (e.g., ItemTemplate, EditItemTemplate), you need to specify which data source fields you want to display. ASP.NET provides a special declarative syntax for specifying data elements, generally referred to as data-binding expressions . The syntax for a data-binding expression is: E.g. <%# expression %> <%# Eval(&quot;LastName&quot;) %> <%# Eval(&quot;Price&quot;, &quot;{0:c}&quot;) %> composite formatting string
  • 13. DataList Control The developer specifies which particular data items in the data source will be displayed in a repeating list. This is done by using data-binding expressions within the ItemTemplate element. <asp:SqlDataSource ID=&quot;dsPubs&quot; runat=&quot;server&quot; ProviderName=&quot;System.Data.SqlClient&quot; ConnectionString=&quot;<%$ ConnectionStrings:BookCatalog %>&quot; SelectCommand=&quot;Select PublisherId,PublisherName From Publishers&quot; /> <asp:DataList ID=&quot;dlstPub&quot; runat=&quot;server&quot; DataSourceID=&quot;dsPubs&quot;> <ItemTemplate> <%# Eval(&quot;PublisherName&quot;) %> </ItemTemplate> </asp:DataList>
  • 14. DataList Control <asp:DataList ID=&quot;dlstPub&quot; runat=&quot;server&quot; DataSourceID=&quot;dsPubs&quot; CellPadding=&quot;5&quot; RepeatLayout=&quot;Table&quot;>   <HeaderTemplate> <h2>Publishers</h2> </HeaderTemplate>   <ItemTemplate> <%# Eval(&quot;PublisherName&quot;) %> </ItemTemplate>   <ItemStyle BackColor=&quot;AntiqueWhite&quot; ForeColor=&quot;Brown&quot; Font-Size=&quot;Medium&quot; Width=&quot;150&quot; Height=&quot;25&quot; />   <AlternatingItemStyle BackColor=&quot;silver&quot; /> <SeparatorStyle BackColor=&quot;crimson&quot; Height=&quot;5&quot; /> <SeparatorTemplate></SeparatorTemplate> </asp:DataList>
  • 16. Repeater Control Displays items in a repeating list. Unlike the DataList control, the Repeater does not have an inherent look for example, it does not by default create a vertical list of data or a HTML <table> element. Instead, you must provide the layout for the control via templates. The Repeater only creates the HTML that you specify within the ItemTemplate element. Although this usually means more work (by the developer) is required to display a simple list of data, it may be preferred by developers who prefer the complete control that the Repeater provides over the generated HTML.
  • 17. Repeater <asp:Repeater ID=&quot;rptArtists&quot; runat=&quot;server&quot; DataSourceID=&quot;dsBooks&quot;>   <HeaderTemplate> <h2 class=&quot;listHeading&quot;>Recent Books</h2> <dl> </HeaderTemplate>   <ItemTemplate> <dt><%# Eval(&quot;Title&quot;) %></dt> <dd class=&quot;bookImage&quot;> <asp:Image ID=&quot;imgBook&quot; runat=&quot;server&quot; ImageUrl='<%# String.Format(&quot;images/{0}.gif&quot;,Eval(&quot;ISBN&quot;)) %>' AlternateText='<%# Eval(&quot;Title&quot;)%>' /> </dd> <dd class=&quot;publisher&quot;> <%# Eval(&quot;PublisherName&quot;) %> (<%# Eval(&quot;YearPublished&quot;) %>) </dd> <dd> <%# Eval(&quot;BriefDescription&quot;) %> </dd> </ItemTemplate>   <FooterTemplate> </dl> </FooterTemplate> </asp:Repeater>
  • 18. FormView Control Displays a single record of data. Provides a built-in mechanism for navigating from record to record; Supports the updating, insertion, and deletion of a record.
  • 19. FormView Control <asp:FormView ID=&quot;frmvBooks&quot; runat=&quot;server&quot; DataSourceID=&quot;dsBooks&quot; CssClass=&quot;entireForm&quot;>   <HeaderTemplate> <h2>Book Details</h2> </HeaderTemplate>   <HeaderStyle CssClass=&quot;singleBookTitle&quot; />   <ItemTemplate> <div class=&quot;singleBook&quot;> ISBN: <br /> <asp:Label ID=&quot;labIsbn&quot; runat=&quot;server&quot; Text='<%# Eval(&quot;ISBN&quot;) %>' CssClass=&quot;dataValues&quot; /> <br /> Title:<br /> <asp:Label ID=&quot;labTitle&quot; runat=&quot;server&quot; Text='<%# Eval(&quot;Title&quot;) %>' CssClass=&quot;dataValues&quot; /> <br /> Publisher:<br /> <asp:Label ID=&quot;labPublisher&quot; runat=&quot;server&quot; Text='<%# Eval(&quot;PublisherName&quot;) %>' CssClass=&quot;dataValues&quot; /> <br /> Year:<br /> <asp:Label ID=&quot;labDesc&quot; runat=&quot;server&quot; Text='<%# Eval(&quot;YearPublished&quot;) %>' CssClass=&quot;dataValues&quot; /> <br /> Description:<br /> <asp:Label ID=&quot;Label1&quot; runat=&quot;server&quot; Text='<%# Eval(&quot;BriefDescription&quot;) %>' CssClass=&quot;dataValues&quot; /> <br /> </div> </ItemTemplate> </asp:FormView>
  • 20. FormView Control Although the FormView control displays a single record of data, it can accept a data source containing multiple records. You can allow the user to move from record to record by setting the control’s AllowPaging property to true.
  • 21. FormView The FormView control can also be used to provide the user with the ability to edit the data in a single record.
  • 22. DetailsView Control Displays a single record of data at a time, provides a way to navigate from record to record, and supports the updating, insertion, or deletion of a record. The DetailsView control differs from the FormView control in that it does not require the use of templates for defining the look of the control. it renders each field in the data source as a row in an HTML <table> element.
  • 23. DetailsView Control <asp:DetailsView ID=&quot;detvBooks&quot; runat=&quot;server&quot; DataSourceID=&quot;dsBooks&quot; />
  • 24. DetailsView Control <asp:DetailsView ID=&quot;detvBooks&quot; runat=&quot;server&quot; DataSourceID=&quot;dsBooks&quot; GridLines=&quot;None&quot; AllowPaging=&quot;true&quot; CellPadding=&quot;4&quot; ForeColor=&quot;#333333&quot; > <RowStyle VerticalAlign=&quot;Top&quot; BackColor=&quot;#EFF3FB&quot;/> <PagerStyle CssClass=&quot;detailsPagerStyle&quot; /> <FieldHeaderStyle BackColor=&quot;#DEE8F5&quot; Font-Bold=&quot;True&quot; /> <HeaderStyle CssClass=&quot;detailsHeaderStyle&quot;/> <AlternatingRowStyle BackColor=&quot;White&quot; /> </asp:DetailsView>
  • 25. GridView Control Provides a way to display data in a tabular (row-column) grid. You can use different field types to customize the visual display of the data within the grid. Also like the DetailsView control, the GridView supports the paging of data as well as the automatic modification and saving of data when bound to a data source control. The GridView also allows the user to sort or select data rows.
  • 26. GridView Control <asp:GridView ID=&quot;grdSample&quot; runat=&quot;server&quot; DataSourceID=&quot;dsBooks&quot; />
  • 27. GridView Control <asp:GridView ID=&quot;grdSample&quot; runat=&quot;server&quot; DataSourceID=&quot;dsBooks&quot; AutoGenerateColumns=&quot;False&quot; BackColor=&quot;White&quot; BorderColor=&quot;#DEDFDE&quot; BorderStyle=&quot;None&quot; BorderWidth=&quot;1px&quot; CellPadding=&quot;4&quot; GridLines=&quot;Vertical&quot; ForeColor=&quot;Black&quot;>   <Columns> <asp:ImageField HeaderText=&quot;&quot; DataImageUrlField=&quot;Isbn&quot; DataImageUrlFormatString=&quot;images/{0}.gif&quot; DataAlternateTextField=&quot;Title&quot; DataAlternateTextFormatString=&quot;Book cover for {0}&quot; ReadOnly=&quot;True&quot; /> <asp:BoundField DataField=&quot;ISBN&quot; HeaderText=&quot;Isbn&quot; ReadOnly=&quot;True&quot;/> <asp:BoundField DataField=&quot;Title&quot; HeaderText=&quot;Title&quot;/> <asp:BoundField DataField=&quot;PublisherName&quot; HeaderText=&quot;Publisher&quot;/> <asp:BoundField DataField=&quot;YearPublished&quot; HeaderText=&quot;Year&quot;/> </Columns>   <RowStyle CssClass=&quot;gridRow&quot; /> <HeaderStyle CssClass=&quot;gridHeader&quot; /> <AlternatingRowStyle CssClass=&quot;gridAlt&quot; /> </asp:GridView>
  • 29. Pagination The GridView control supports pagination . That is, rather than display all the records in the data source, pagination lets the control break its listing up into multiple, smaller pages displaying a subset of the complete data. the user can then move to a specific page of data via pagination navigation buttons. Pagination can be enabled for any GridView , FormView , or DetailsView control by enabling its AllowPaging property. The number of records to appear in each page can be set via the PageSize property.
  • 30. Pagination How does it work? The answer depends on what type of data source control is being used. If a SqlDataSource control is being used, pagination effectively operates at the control level. If an ObjectDataSource control is being used, pagination must be implemented by the underlying object.
  • 31. Pagination In a GridView with pagination using a SqlDataSource control, all the records that match the SELECT statement are read and stored into an internal DataSet every time the page is requested or posted back, regardless of whether pagination is enabled or not enabled. If the SELECT statement returns 100000 records, but the GridView only displays 10 records per page, this is clearly an inefficient approach for a frequently requested page. In such a case, it would be better to refactor so that only the required data for the page is being requested by the database. This can be done at the DBMS level or at an ObjectDataSource level.
  • 32. GridView Sorting The GridView control allows the user to change the visual sort order of the data displayed within the control. When sorting is enabled for the GridView (by setting the AllowSorting property of the control to true), the user can change the sort order of the data by clicking the hyperlinked column header for that field. Furthermore, the user can toggle between an ascending or descending sort order.
  • 33. GridView Sorting <asp:GridView ID=&quot;grdSample&quot; runat=&quot;server&quot; DataSourceID=&quot;dsBooks&quot; AutoGenerateColumns=&quot;False&quot; CellPadding=&quot;4&quot; GridLines=&quot;Vertical&quot; CssClass=&quot;bookList&quot; AllowSorting=&quot;true&quot; >   <Columns> <asp:BoundField DataField=&quot;ISBN&quot; HeaderText=&quot;Isbn&quot; SortExpression=&quot;Isbn&quot; /> <asp:BoundField DataField=&quot;Title&quot; HeaderText=&quot;Title&quot; SortExpression=&quot;Title&quot; /> <asp:BoundField DataField=&quot;PublisherName&quot; HeaderText=&quot;Publisher&quot; SortExpression=&quot;PublisherName&quot; /> <asp:BoundField DataField=&quot;YearPublished&quot; HeaderText=&quot;Year&quot; SortExpression=&quot;YearPublished&quot; /> </Columns> … </asp:GridView>
  • 34. Editing Data in GridView The GridView control supports the in-place editing of data within a row by the user. In fact, you can add editing to a GridView control in almost exactly the same manner as with the DetailsView control.
  • 35. Nested GridView Controls You can nest GridView controls in order to display data that has a one-to-many relationship.