CommandField.ShowEditButton Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy przycisk Edytuj jest wyświetlany w CommandField polu.

public:
 virtual property bool ShowEditButton { bool get(); void set(bool value); };
public virtual bool ShowEditButton { get; set; }
member this.ShowEditButton : bool with get, set
Public Overridable Property ShowEditButton As Boolean

Wartość właściwości

true aby wyświetlić przycisk Edytuj w elemecie CommandField; w przeciwnym razie false. Wartość domyślna to false.

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą ShowEditButton właściwości wyświetlić przycisk Edytuj dla każdego rekordu w kontrolce GridView .


<%@ 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>CommandField Example</title>
</head>
<body>
    <form id="form1" runat="server">
      
      <h3>CommandField Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="false"
        datakeynames="CustomerID"  
        runat="server">
        
        <columns>
          <asp:commandfield showeditbutton="true"
            buttontype="Image"
            editimageurl="~\Images\EditButton.jpg"
            cancelimageurl="~\Images\CancelButton.jpg"
            updateimageurl="~\Images\UpdateButton.jpg"
            headertext="Edit Controls"/>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </columns>
        
      </asp:gridview>
            
      <!-- 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="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        updatecommand="Update Customers Set CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID = @CustomerID)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </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>CommandField Example</title>
</head>
<body>
    <form id="form1" runat="server">
      
      <h3>CommandField Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="false"
        datakeynames="CustomerID"  
        runat="server">
        
        <columns>
          <asp:commandfield showeditbutton="true"
            buttontype="Image"
            editimageurl="~\Images\EditButton.jpg"
            cancelimageurl="~\Images\CancelButton.jpg"
            updateimageurl="~\Images\UpdateButton.jpg"
            headertext="Edit Controls"/>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </columns>
        
      </asp:gridview>
            
      <!-- 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="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        updatecommand="Update Customers Set CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country Where (CustomerID = @CustomerID)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

Uwagi

ShowEditButton Użyj właściwości , aby określić, czy przycisk Edytuj jest wyświetlany w CommandField polu dla każdego rekordu w kontrolce źródła danych. Przycisk Edytuj umożliwia edytowanie wartości rekordu.

Gdy użytkownik kliknie przycisk Edytuj, kontrolki wejściowe są wyświetlane dla każdego pola w rekordzie. Przycisk Edytuj dla rekordu jest zastępowany przyciskiem Aktualizuj i przyciskiem Anuluj, a wszystkie inne przyciski poleceń dla rekordu są ukryte. Kliknięcie przycisku Aktualizuj aktualizuje rekord przy użyciu nowych wartości w źródle danych, a kliknięcie przycisku Anuluj anuluje operację.

Uwaga

Gdy kontrolka powiązana z danymi jest używana w połączeniu z kontrolką źródła danych (taką jak kontrolka SqlDataSource ), kontrolka powiązana z danymi może korzystać z możliwości kontroli źródła danych i zapewnić funkcję automatycznego aktualizowania. W przypadku innych źródeł danych należy podać procedury wykonywania operacji aktualizacji podczas odpowiedniego zdarzenia dla kontrolki powiązanej z danymi.

ButtonType Gdy właściwość CommandField pola jest ustawiona na ButtonType.Button lub ButtonType.Link, użyj EditText właściwości , aby określić tekst do wyświetlenia dla przycisku Edytuj. Możesz też wyświetlić obraz, ustawiając ButtonType najpierw właściwość na ButtonType.Image , a następnie ustawiając EditImageUrl właściwość .

Dotyczy

Zobacz też