Using DetailsView : DetailsView « Data Binding « ASP.NET Tutorial






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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="sourceEmployees" 
                           runat="server" 
                           ConnectionString="<%$ ConnectionStrings:Northwind %>"
                           ProviderName="System.Data.SqlClient" 
                           SelectCommand="SELECT * FROM Employees"/>
            <asp:DetailsView ID="DetailsView1" 
                             runat="server" 
                             AutoGenerateRows="False"
                             BorderStyle="Double" 
                             CellPadding="4" 
                             DataKeyNames="EmployeeID" 
                             DataSourceID="sourceEmployees"
                             Font-Names="Verdana" 
                             Font-Size="Small" 
                             ForeColor="#333333" 
                             GridLines="None" 
                             Height="50px"
                             Width="509px" 
                             AutoGenerateDeleteButton="True" 
                             AutoGenerateEditButton="True" 
                             AutoGenerateInsertButton="True" 
                             AllowPaging="True">
                <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <CommandRowStyle BackColor="#FFFFC0" Font-Bold="True" />
                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                <FieldHeaderStyle BackColor="#FFFF99" Font-Bold="True" />
                <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                <Fields>
                    <asp:BoundField DataField="EmployeeID" 
                                    HeaderText="EmployeeID" 
                                    InsertVisible="False"
                                    ReadOnly="True" 
                                    SortExpression="EmployeeID"/>
                    <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
                    <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:BoundField DataField="TitleOfCourtesy" HeaderText="TitleOfCourtesy" SortExpression="TitleOfCourtesy" />
                    <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
                    <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                    <asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region" />
                    <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
                    <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
                </Fields>
                <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
            </asp:DetailsView>
         </div>
    </form>
</body>
</html>

File: Web.config


<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <appSettings/>
      <connectionStrings>
        <add name="Northwind" connectionString="Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI"/>
      </connectionStrings>
</configuration>








19.12.DetailsView
19.12.1.Using DetailsView
19.12.2.Link asp:DetaisView with asp:SqlDataSource
19.12.3.Bind a DetailsView control programmatically to a data source
19.12.4.Using BoundFields with the DetailsView control.
19.12.5.Displaying Empty Data with the DetailsView Control
19.12.6.Displaying content when no results are returned.
19.12.7.Paging Through Data with the DetailsView Control
19.12.8.Customizing the Paging Interface
19.12.9.Inserting a record with the DetailsView control.
19.12.10.Format DetailsView