DetailsView.DefaultMode Właściwość

Definicja

Pobierz lub ustawia domyślny tryb wprowadzania danych kontrolki DetailsView .

public:
 virtual property System::Web::UI::WebControls::DetailsViewMode DefaultMode { System::Web::UI::WebControls::DetailsViewMode get(); void set(System::Web::UI::WebControls::DetailsViewMode value); };
public virtual System.Web.UI.WebControls.DetailsViewMode DefaultMode { get; set; }
member this.DefaultMode : System.Web.UI.WebControls.DetailsViewMode with get, set
Public Overridable Property DefaultMode As DetailsViewMode

Wartość właściwości

DetailsViewMode

Jedna z DetailsViewMode wartości. Wartość domyślna to DetailsViewMode.ReadOnly.

Wyjątki

Określona wartość nie jest jedną z DetailsViewMode wartości wyliczenia.

Przykłady

Poniższy przykład kodu pokazuje, jak za pomocą DefaultMode właściwości określić, że kontrolka DetailsView powinna pozostać w trybie edycji po zaktualizowaniu rekordu.


<%@ 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>DetailsView DefaultMode Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView DefaultMode Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogenerateeditbutton="true"   
          autogeneraterows="true"
          allowpaging="true"
          defaultmode="Edit"   
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value   -->
        <!-- from the web.config file.                            -->
        <asp:SqlDataSource ID="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
          InsertCommand="INSERT INTO [Customers]([CustomerID],
            [CompanyName], [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"

          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>

<%@ 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>DetailsView DefaultMode Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView DefaultMode Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogenerateeditbutton="true"   
          autogeneraterows="true"
          allowpaging="true"
          defaultmode="Edit"   
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value   -->
        <!-- from the web.config file.                            -->
        <asp:SqlDataSource ID="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
          InsertCommand="INSERT INTO [Customers]([CustomerID],
            [CompanyName], [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"

          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>

Uwagi

DefaultMode Użyj właściwości , aby określić, czy DetailsView kontrolka powraca do edycji, wstawiania lub trybu tylko do odczytu po wykonaniu operacji edycji lub wstawiania. Domyślnie kontrolka DetailsView powraca do trybu tylko do odczytu. Można jednak zachować DetailsView kontrolę w trybie edycji lub wstawiania, ustawiając tę właściwość na odpowiednią wartość. W poniższej tabeli wymieniono różne wartości trybu.

Tryb Opis
DetailsViewMode.Edit Kontrolka DetailsView jest w trybie edycji, który umożliwia użytkownikowi aktualizowanie wartości rekordu.
DetailsViewMode.Insert Kontrolka DetailsView jest w trybie wstawiania, co umożliwia użytkownikowi dodanie nowego rekordu do źródła danych.
DetailsViewMode.ReadOnly Kontrolka DetailsView jest w trybie tylko do odczytu, który jest normalnym trybem wyświetlania.

Dotyczy

Zobacz też