CommandField.ShowInsertButton Tulajdonság

Definíció

Beolvas vagy beállít egy értéket, amely jelzi, hogy megjelenik-e egy Új gomb egy CommandField mezőben.

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

Tulajdonság értéke

true új gomb CommandFieldmegjelenítéséhez a ; egyéb esetben false. Az alapértelmezett érték a false.

Példák

Az alábbi példakód bemutatja, hogyan jeleníthet meg új gombot egy vezérlőben ShowInsertButton a DetailsView tulajdonság használatával, amely lehetővé teszi, hogy a felhasználó új rekordot adjon hozzá az adatforráshoz.


<%@ 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:detailsview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneraterows="false"
        datakeynames="CustomerID"  
        allowpaging="true" 
        runat="server">
        
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="CompanyName"/>
          <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"/>
          <asp:commandfield showinsertbutton="true"
            showheader="true"
            headertext="Add Customer"/>
        </fields>
        
      </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="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        insertcommand="Insert Into [Customers]([CustomerID], [CompanyName], [City], [PostalCode], [Country]) Values (@CustomerID, @CompanyName, @City, @PostalCode, @Country)"
        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:detailsview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneraterows="false"
        datakeynames="CustomerID"  
        allowpaging="true" 
        runat="server">
        
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID" />
          <asp:boundfield datafield="CompanyName"
            headertext="CompanyName"/>
          <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"/>
          <asp:commandfield showinsertbutton="true"
            showheader="true"
            headertext="Add Customer"/>
        </fields>
        
      </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="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        insertcommand="Insert Into [Customers]([CustomerID], [CompanyName], [City], [PostalCode], [Country]) Values (@CustomerID, @CompanyName, @City, @PostalCode, @Country)"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

Megjegyzések

ShowInsertButton A tulajdonság használatával megadhatja, hogy megjelenik-e egy Új gomb egy CommandField mezőben. Az Új gomb csak egyszer jelenik meg a CommandField mezőben, és lehetővé teszi, hogy a felhasználó új rekordot vegyen fel az adatforrásba.

Note

Ez a tulajdonság csak a beszúrási műveleteket támogató, adathoz kötött vezérlőkre vonatkozik, például a vezérlőre DetailsView .

Amikor a felhasználó az Új gombra kattint, a beviteli vezérlők megjelennek az adatkötött vezérlőelemben megjelenő minden mezőhöz, így a felhasználó megadhatja az új rekord értékeit. Az Új gombot felváltja a Beszúrás és a Mégse gomb, és a CommandField mező összes többi parancsgombja el van rejtve. A Beszúrás gombra kattintva hozzáadja a rekordot az adatforráshoz, míg a Mégse gombra kattintva megszakítja a műveletet.

Note

Ha az adatforrás-vezérlővel (például SqlDataSource vezérlővel) együtt használ adatkötéses vezérlőt, az adathoz kötött vezérlő kihasználhatja az adatforrás-vezérlő képességeit, és automatikus beszúrási funkciókat biztosíthat. Más adatforrások esetében meg kell adnia a beszúrási művelet végrehajtásához szükséges rutinokat az adatkötött vezérlőelem megfelelő eseménye során.

Ha egy ButtonTypeCommandField mező tulajdonsága a következőre ButtonType.Button van állítva, vagy ButtonType.Linka tulajdonság használatával NewText adja meg az Új gombhoz megjelenítendő szöveget. Másik lehetőségként megjeleníthet egy képet úgy is, hogy először a ButtonType tulajdonságot a tulajdonságra ButtonType.Image állítja, majd a NewImageUrl tulajdonságot.

A következőre érvényes:

Lásd még