다음을 통해 공유


CommandField.ShowInsertButton 속성

정의

필드에 새로 만들기 단추가 표시되는 CommandField 지 여부를 나타내는 값을 가져오거나 설정합니다.

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

속성 값

에 새로 만들기 단추를 표시하려면 />이고, 그렇지 않으면 . 기본값은 false입니다.

예제

다음 코드 예제에서는 사용자가 데이터 원본에 새 레코드를 추가할 수 있도록 컨트롤에 DetailsView 새 단추를 표시 하는 속성을 사용 ShowInsertButton 하는 방법을 보여 줍니다.


<%@ 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>

설명

새 단추가 ShowInsertButton 필드에 표시되는 CommandField 지 여부를 지정하려면 이 속성을 사용합니다. 새 단추는 필드에 한 번만 CommandField 표시되며 사용자가 데이터 원본에 새 레코드를 추가할 수 있습니다.

메모

이 속성은 컨트롤과 같은 삽입 작업을 지원하는 데이터 바인딩된 컨트롤에 DetailsView 만 적용됩니다.

사용자가 새로 만들기 단추를 클릭하면 데이터 바인딩된 컨트롤에 표시되는 각 필드에 대한 입력 컨트롤이 표시되므로 사용자가 새 레코드의 값을 입력할 수 있습니다. 새로 만들기 단추는 삽입 단추와 취소 단추로 대체되고 필드의 CommandField 다른 모든 명령 단추는 숨겨집니다. 삽입 단추를 클릭하면 레코드가 데이터 원본에 추가되는 반면 취소 단추를 클릭하면 작업이 취소됩니다.

메모

데이터 바인딩된 컨트롤을 데이터 소스 컨트롤(예: SqlDataSource 컨트롤)과 함께 사용하는 경우 데이터 바인딩된 컨트롤은 데이터 원본 컨트롤의 기능을 활용하고 자동 삽입 기능을 제공할 수 있습니다. 다른 데이터 원본의 경우 데이터 바인딩된 컨트롤에 대한 적절한 이벤트 중에 삽입 작업을 수행하는 루틴을 제공해야 합니다.

필드의 ButtonTypeCommandField 속성을 설정 ButtonType.Button 하거나 ButtonType.Link새 단추에 표시할 텍스트를 지정하려면 이 속성을 사용합니다 NewText . 또는 먼저 속성을 설정한 다음 속성을 설정 ButtonTypeNewImageUrl 하여 이미지를 표시할 ButtonType.Image 수 있습니다.

적용 대상

추가 정보