Partager via


Syntaxe déclarative du contrôle serveur Web DetailsView

Mise à jour : novembre 2007

Affiche les valeurs d'un enregistrement unique d'une source de données dans un tableau, où chaque ligne de données représente un champ de l'enregistrement. Le contrôle DetailsView vous permet de modifier, de supprimer et d'insérer des enregistrements.

<asp:DetailsView
    AccessKey="string"
    AllowPaging="True|False"
    AutoGenerateDeleteButton="True|False"
    AutoGenerateEditButton="True|False"
    AutoGenerateInsertButton="True|False"
    AutoGenerateRows="True|False"
    BackColor="color name|#dddddd"
    BackImageUrl="uri"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    Caption="string"
    CaptionAlign="NotSet|Top|Bottom|Left|Right"
    CellPadding="integer"
    CellSpacing="integer"
    CssClass="string"
    DataKeyNames="string"
    DataMember="string"
    DataSource="string"
    DataSourceID="string"
    DefaultMode="ReadOnly|Edit|Insert"
    EmptyDataText="string"
    Enabled="True|False"
    EnablePagingCallbacks="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    FooterText="string"
    ForeColor="color name|#dddddd"
    GridLines="None|Horizontal|Vertical|Both"
    HeaderText="string"
    Height="size"
    HorizontalAlign="NotSet|Left|Center|Right|Justify"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDataBound="DataBound event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnItemCommand="ItemCommand event handler"
    OnItemCreated="ItemCreated event handler"
    OnItemDeleted="ItemDeleted event handler"
    OnItemDeleting="ItemDeleting event handler"
    OnItemInserted="ItemInserted event handler"
    OnItemInserting="ItemInserting event handler"
    OnItemUpdated="ItemUpdated event handler"
    OnItemUpdating="ItemUpdating event handler"
    OnLoad="Load event handler"
    OnModeChanged="ModeChanged event handler"
    OnModeChanging="ModeChanging event handler"
    OnPageIndexChanged="PageIndexChanged event handler"
    OnPageIndexChanging="PageIndexChanging event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    PageIndex="integer"
    PagerSettings-FirstPageImageUrl="uri"
    PagerSettings-FirstPageText="string"
    PagerSettings-LastPageImageUrl="uri"
    PagerSettings-LastPageText="string"
    PagerSettings-Mode="NextPrevious|Numeric|NextPreviousFirstLast|NumericFirstLast"
    PagerSettings-NextPageImageUrl="uri"
    PagerSettings-NextPageText="string"
    PagerSettings-PageButtonCount="integer"
    PagerSettings-Position="Bottom|Top|TopAndBottom"
    PagerSettings-PreviousPageImageUrl="uri"
    PagerSettings-PreviousPageText="string"
    PagerSettings-Visible="True|False"
    runat="server"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    ToolTip="string"
    Visible="True|False"
    Width="size"
>
        <AlternatingRowStyle />
        <CommandRowStyle />
        <EditRowStyle />
        <EmptyDataRowStyle />
        <EmptyDataTemplate>
            <!-- child controls -->
        </EmptyDataTemplate>
        <FieldHeaderStyle />
        <Fields>
                <asp:BoundField
                    AccessibleHeaderText="string"
                    ApplyFormatInEditMode="True|False"
                    ConvertEmptyStringToNull="True|False"
                    DataField="string"
                    DataFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    HtmlEncode="True|False"
                    InsertVisible="True|False"
                    NullDisplayText="string"
                    ReadOnly="True|False"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:BoundField>
                <asp:ButtonField
                    AccessibleHeaderText="string"
                    ButtonType="Button|Image|Link"
                    CausesValidation="True|False"
                    CommandName="string"
                    DataTextField="string"
                    DataTextFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    ImageUrl="uri"
                    InsertVisible="True|False"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Text="string"
                    ValidationGroup="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:ButtonField>
                <asp:CheckBoxField
                    AccessibleHeaderText="string"
                    DataField="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    InsertVisible="True|False"
                    ReadOnly="True|False"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Text="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:CheckBoxField>
                <asp:CommandField
                    AccessibleHeaderText="string"
                    ButtonType="Button|Image|Link"
                    CancelImageUrl="uri"
                    CancelText="string"
                    CausesValidation="True|False"
                    DeleteImageUrl="uri"
                    DeleteText="string"
                    EditImageUrl="uri"
                    EditText="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    InsertImageUrl="uri"
                    InsertText="string"
                    InsertVisible="True|False"
                    NewImageUrl="uri"
                    NewText="string"
                    SelectImageUrl="uri"
                    SelectText="string"
                    ShowCancelButton="True|False"
                    ShowDeleteButton="True|False"
                    ShowEditButton="True|False"
                    ShowHeader="True|False"
                    ShowInsertButton="True|False"
                    ShowSelectButton="True|False"
                    SortExpression="string"
                    UpdateImageUrl="uri"
                    UpdateText="string"
                    ValidationGroup="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:CommandField>
                <asp:DynamicField
                    AccessibleHeaderText="string"
                    ApplyFormatInEditMode="True|False"
                    ConvertEmptyStringToNull="True|False"
                    DataField="string"
                    DataFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                                        HtmlEncode="True|False"
                    InsertVisible="True|False"
                                        NullDisplayText="string"
                    ShowHeader="True|False"
                    UIHint="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                                </asp:DynamicField>
                <asp:HyperLinkField
                    AccessibleHeaderText="string"
                    DatahrefFields="string"
                    DatahrefFormatString="string"
                    DataTextField="string"
                    DataTextFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    InsertVisible="True|False"
                    href="uri"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Target="string|_blank|_parent|_search|_self|_top"
                    Text="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:HyperLinkField>
                <asp:ImageField
                    AccessibleHeaderText="string"
                    AlternateText="string"
                    ConvertEmptyStringToNull="True|False"
                    DataAlternateTextField="string"
                    DataAlternateTextFormatString="string"
                    DataImageUrlField="string"
                    DataImageUrlFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    InsertVisible="True|False"
                    NullDisplayText="string"
                    NullImageUrl="uri"
                    ReadOnly="True|False"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Visible="True|False"
>
                        <ControlStyle />
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:ImageField>
                <asp:TemplateField
                    AccessibleHeaderText="string"
                    ConvertEmptyStringToNull="True|False"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    InsertVisible="True|False"
                    ShowHeader="True|False"
                    SortExpression="string"
                    Visible="True|False"
>
                            <ControlStyle />
                            <FooterStyle />
                            <HeaderStyle />
                            <ItemStyle />
                        <AlternatingItemTemplate>
                            <!-- child controls -->
                        </AlternatingItemTemplate>
                        <EditItemTemplate>
                            <!-- child controls -->
                        </EditItemTemplate>
                        <FooterTemplate>
                            <!-- child controls -->
                        </FooterTemplate>
                        <HeaderTemplate>
                            <!-- child controls -->
                        </HeaderTemplate>
                        <InsertItemTemplate>
                            <!-- child controls -->
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <!-- child controls -->
                        </ItemTemplate>
                </asp:TemplateField>
        </Fields>
        <FooterStyle />
        <FooterTemplate>
            <!-- child controls -->
        </FooterTemplate>
        <HeaderStyle />
        <HeaderTemplate>
            <!-- child controls -->
        </HeaderTemplate>
        <InsertRowStyle />
        <PagerSettings
            FirstPageImageUrl="uri"
            FirstPageText="string"
            LastPageImageUrl="uri"
            LastPageText="string"
            Mode="NextPrevious|Numeric|NextPreviousFirstLast|
                NumericFirstLast"
            NextPageImageUrl="uri"
            NextPageText="string"
            OnPropertyChanged="PropertyChanged event handler"
            PageButtonCount="integer"
            Position="Bottom|Top|TopAndBottom"
            PreviousPageImageUrl="uri"
            PreviousPageText="string"
            Visible="True|False"
        />
        <PagerStyle />
        <PagerTemplate>
            <!-- child controls -->
        </PagerTemplate>
        <RowStyle        />
</asp:DetailsView>

Notes

Le contrôle DetailsView permet d'afficher un enregistrement unique d'une source de données dans un tableau où chaque champ de l'enregistrement s'affiche dans une ligne du tableau. Il peut être utilisé en association avec un contrôle GridView pour les scénarios maîtres/détails.

L'objet DynamicField est un nouveau champ introduit dans .NET Framework 3.5 SP1. Il peut être utilisé par un contrôle DetailsView dans les applications Dynamic Data ASP.NET. Pour plus d'informations sur Dynamic Data, consultez Vue d'ensemble de Dynamic Data ASP.NET.

Exemple

L'exemple de code suivant montre comment utiliser un contrôle DetailsView en association avec un contrôle GridView pour un scénario maître/détail simple. Il affiche les détails d'un élément sélectionné dans le contrôle GridView.

Pour plus d'informations sur l'utilisation du contrôle DetailsView, consultez Vue d'ensemble du contrôle serveur Web DetailsView.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <table>
        <tr>
          <td>
            <asp:GridView ID="GridView1" runat="server" 
              AutoGenerateColumns="False" DataSourceID="Customers"
              DataKeyNames="CustomerID">
              <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
              </Columns>
            </asp:GridView>
          </td>
          <td valign="top">
            <asp:DetailsView ID="DetailsView1" runat="server" 
              AutoGenerateRows="True" DataKeyNames="CustomerID"
              DataSourceID="Details" Height="50px" Width="301px">
            </asp:DetailsView>
          </td>
        </tr>
      </table>

      &nbsp;&nbsp;
      <asp:SqlDataSource ID="Details" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT * FROM [Customers] WHERE ([CustomerID] = @CustomerID)">
        <SelectParameters>
          <asp:ControlParameter ControlID="GridView1" Name="CustomerID" 
            PropertyName="SelectedValue"
            Type="String" />
        </SelectParameters>
      </asp:SqlDataSource>
      <asp:SqlDataSource ID="Customers" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID] FROM [Customers]">
      </asp:SqlDataSource>
    </div>
  </form>
</body>
</html>
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <table>
        <tr>
          <td>
            <asp:GridView ID="GridView1" runat="server" 
              AutoGenerateColumns="False" DataSourceID="Customers"
              DataKeyNames="CustomerID">
              <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
              </Columns>
            </asp:GridView>
          </td>
          <td valign="top">
            <asp:DetailsView ID="DetailsView1" runat="server" 
              AutoGenerateRows="True" DataKeyNames="CustomerID"
              DataSourceID="Details" Height="50px" Width="301px">
            </asp:DetailsView>
          </td>
        </tr>
      </table>

      &nbsp;&nbsp;
      <asp:SqlDataSource ID="Details" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT * FROM [Customers] WHERE ([CustomerID] = @CustomerID)">
        <SelectParameters>
          <asp:ControlParameter ControlID="GridView1" Name="CustomerID" 
            PropertyName="SelectedValue"
            Type="String" />
        </SelectParameters>
      </asp:SqlDataSource>
      <asp:SqlDataSource ID="Customers" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID] FROM [Customers]">
      </asp:SqlDataSource>
    </div>
  </form>
</body>
</html>

Voir aussi

Concepts

Vue d'ensemble de Dynamic Data ASP.NET

Référence

Vue d'ensemble du contrôle serveur Web DetailsView

DetailsView