How to use DetailsView in

DetailsView Web Server Control
DetailsView is an web server control. detailsview display a single record from a data source. detailsview provide a way to show, edit, update, insert or delete a single record at a time. this control display each field of a record on its own line. some time .net developer use detailsview in a master detail page. 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. detailsview create a user interface for paging if we set the AllowPaging property value to true.

.net developers can populate a detailsview with data using many data source control such as SqlDataSource, LinqDataSource, ObjectDataSource control. detailsview provide a UI that allow user to update of a bound record. an editable view displays additional row that contains Edit, Insert and Delete command button. after clicking a command button detailsview redisplay row with controls that allow users to modify the row contents. detailsview display data automatically when AutoGenerateRows property value is set to true. detailsview control uses textboxes to display data in a BoundField. detailsview render checkbox to display Boolean data. developers can customize input control displayed in edit mode by using a TemplateField.

detailsview insert data by passes the values to be inserted in the data source using Values dictionary collection.

detailsview PagerSettings property allow us to customize the appearance of paging user interface. pager supports several display mode. we can control it by PagerSettings Mode property. possible modes are NextPrevious, NextPreviousFirstLast, Numeric and NumericFirstLast.

we can enable detailsview built-in edit, insert and delete functionality by setting AutoGenerateEditButton, AutoGenerateInsertButton and AutoGenerateDeleteButton properties value to true.

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. in a template we can bind controls to data using Eval and Bind methods.

following c# example source code demonstare us how can we use detailsview server control in environment.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">


<html xmlns="">
<head runat="server">
    <title> DetailsView example: how to use DetailsView</title>
    <form id="form1" runat="server">
        <h2 style="color:Navy">DetailsView Example</h2>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT ProductID, ProductName, UnitPrice FROM Products">
        <asp:DetailsView ID="DetailsView" runat="server" DataSourceID="SqlDataSource1" AllowPaging="true" ForeColor="DarkGreen" BackColor="Snow" BorderColor="Tomato">
Related examples