Link asp:DetaisView with asp:SqlDataSource : DetailsView « Data Binding « ASP.NET Tutorial






<%@ Page Language="VB" AutoEventWireup="false" %>

<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="SqlDataSource1" 
                           runat="server" ConnectionString="YourConnectionString"
                           SelectCommand="SELECT * FROM [Books]"></asp:SqlDataSource>
    
    </div>
        <asp:DetailsView ID="DetailsView1" 
                         runat="server" 
                         AllowPaging="True" 
                         AutoGenerateRows="False"
                         BackColor="LightGoldenrodYellow" 
                         BorderColor="Tan" 
                         BorderWidth="1px" 
                         CellPadding="2"
                         DataKeyNames= "BookID" 
                         DataSourceID="SqlDataSource1" 
                         ForeColor="Black" 
                         GridLines="None"
                         Height="50px" 
                         Width="125px">
            <PagerSettings Mode="NextPrevious" NextPageText="Next &amp;gt;" PreviousPageText="&amp;lt; Previous" />
            <FooterStyle BackColor="Tan" />
            <EditRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
            <Fields>
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" />
                <asp:BoundField DataField="PageCount" HeaderText="Pages" SortExpression="PageCount" />
                <asp:BoundField DataField="YearPublished" HeaderText="Published" SortExpression="YearPublished" />
                <asp:BoundField DataField="Price" DataFormatString="{0:c}" HeaderText="Price" HtmlEncode="False"
                    SortExpression="Price" />
                <asp:BoundField DataField="LastReadOn" DataFormatString="{0:d}" HeaderText="Last Read"
                    HtmlEncode="False" SortExpression="LastReadOn" />
            </Fields>
            <HeaderStyle BackColor="Tan" Font-Bold="True" />
            <AlternatingRowStyle BackColor="PaleGoldenrod" />
        </asp:DetailsView>
        <br />
    </form>
</body>
</html>



File: Web.config

<?xml version="1.0"?>
<configuration>
    <connectionStrings>
        <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyFirstDatabase.mdf;Integrated Security=True;User Instance=True"
            providerName="System.Data.SqlClient" />
    </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