이 문서는 기계로 번역한 것입니다. 원본 텍스트를 보려면 포인터를 문서의 문장 위로 올리십시오. 추가 정보
번역
원본
이 항목은 아직 평가되지 않았습니다.- 이 항목 평가

FormViewCommandEventArgs 클래스

ItemCommand 이벤트에 대한 데이터를 제공합니다.

System.Object
  System.EventArgs
    System.Web.UI.WebControls.CommandEventArgs
      System.Web.UI.WebControls.FormViewCommandEventArgs

네임스페이스:  System.Web.UI.WebControls
어셈블리:  System.Web(System.Web.dll)
public class FormViewCommandEventArgs : CommandEventArgs

FormViewCommandEventArgs 형식에서는 다음과 같은 멤버를 노출합니다.

  이름설명
Public 메서드FormViewCommandEventArgs FormViewCommandEventArgs 클래스의 새 인스턴스를 초기화합니다.
위쪽
  이름설명
Public 속성CommandArgument명령 인수를 가져옵니다. (CommandEventArgs에서 상속됨)
Public 속성CommandName명령 이름을 가져옵니다. (CommandEventArgs에서 상속됨)
Public 속성CommandSource이벤트를 발생시킨 컨트롤을 가져옵니다.
Public 속성Handled컨트롤 이벤트를 처리 했는지 여부를 나타내는 값을 가져오거나 설정 합니다.
위쪽
  이름설명
Public 메서드Equals(Object)지정한 개체와 현재 개체가 같은지 여부를 확인합니다. (Object에서 상속됨)
Protected 메서드Finalize

가비지 수집자 에서 회수하기 전에 개체에서 리소스를 해제하고 다른 정리 작업을 수행할 수 있게 합니다.

(Object에서 상속됨)
Public 메서드GetHashCode특정 형식에 대한 해시 함수 역할을 합니다. (Object에서 상속됨)
Public 메서드GetType현재 인스턴스의 Type을 가져옵니다. (Object에서 상속됨)
Protected 메서드MemberwiseClone현재 Object의 단순 복사본을 만듭니다. (Object에서 상속됨)
Public 메서드ToString현재 개체를 나타내는 문자열을 반환합니다. (Object에서 상속됨)
위쪽

ItemCommand 이벤트는 FormView 컨트롤에 있는 단추를 클릭하면 발생합니다. 이를 통해 이 이벤트가 발생할 때마다 사용자 지정 루틴을 수행하는 이벤트 처리 메서드를 제공할 수 있습니다.

FormView 컨트롤 내의 단추를 클릭해도 컨트롤의 일부 기본 제공 기능이 호출될 수 있습니다. 이러한 작업 중 하나를 수행하려면 단추의 CommandName 속성을 다음 표의 값 중 하나로 설정합니다.

CommandName 값

설명

"Cancel"

편집 또는 삽입 작업을 취소하고 FormView 컨트롤을 DefaultMode 속성에 지정된 모드로 되돌립니다. ModeChanged ModeChanging 이벤트를 발생시킵니다.

"Delete"

현재 레코드를 삭제합니다. ItemDeleted ItemDeleting 이벤트를 발생시킵니다.

"Edit"

FormView 컨트롤을 편집 모드로 전환합니다. ModeChanged ModeChanging 이벤트를 발생시킵니다.

"Insert"

데이터 소스에 현재 레코드를 삽입합니다. ItemInserted ItemInserting 이벤트를 발생시킵니다.

"New"

FormView 컨트롤을 삽입 모드로 전환합니다. ModeChanged ModeChanging 이벤트를 발생시킵니다.

"Page"

페이징 작업을 수행합니다. 단추의 CommandArgument 속성을 "First", "Last", "Next", "Prev" 또는 페이지 번호로 설정하여 수행할 페이징 작업의 유형을 지정합니다. PageIndexChanged PageIndexChanging 이벤트를 발생시킵니다.

"Update"

데이터 소스의 현재 레코드를 업데이트합니다. ItemUpdated ItemUpdating 이벤트를 발생시킵니다.

위의 표에 나열된 단추를 클릭하면 ItemCommand 이벤트가 발생하지만 작업에는 이 표에 나열된 이벤트를 사용하는 것이 좋습니다.

FormViewCommandEventArgs 개체는 이벤트 처리 메서드에 전달되며, 이를 통해 클릭된 단추의 명령 이름과 명령 인수를 확인할 수 있습니다. 명령 이름과 명령 인수를 확인하려면 각각 CommandNameCommandArgument 속성을 사용합니다. 또한 CommandSource 속성을 사용하여 이벤트를 발생시킨 단추 컨트롤에 액세스할 수도 있습니다.

이벤트 처리에 대한 자세한 내용은 이벤트 사용를 참조하십시오.

FormViewCommandEventArgs 클래스의 인스턴스에 대한 초기 속성 값 목록을 보려면 FormViewCommandEventArgs 생성자를 참조하십시오.

다음 예제에서는 ItemCommand 이벤트에 대한 이벤트 처리기에 전달된 FormViewCommandEventArgs 개체를 사용하여 FormView 컨트롤 내의 단추 중에서 사용자가 클릭한 단추를 확인하는 방법을 보여 줍니다.

보안 정보보안 정보

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지에서는 사용자 입력 내용에 스크립트나 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하십시오.



<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void ProductFormView_ItemCommand(Object sender, FormViewCommandEventArgs e)
  {

    // The ItemCommand event is raised when any button within
    // the FormView control is clicked. Use the CommandName property 
    // to determine which button was clicked. 
    if (e.CommandName == "Add")
    {

      // Add the product to the ListBox control. 

      // Use the Row property to retrieve the data row.
      FormViewRow row = ProductFormView.Row;

      // Retrieve the ProductNameLabel control from
      // the data row.
      Label productNameLabel = (Label)row.FindControl("ProductNameLabel");

      // Retrieve the QuantityTextBox control from
      // the data row.
      TextBox quantityTextBox = (TextBox)row.FindControl("QuantityTextBox");

      if (productNameLabel != null && quantityTextBox != null)
      {    
        // Get the product name from the ProductNameLabel control.
        string name = productNameLabel.Text;

        // Get the quantity from the QuantityTextBox control.
        string quantity = quantityTextBox.Text;

        // Create the text to display in the ListBox control.
        string description = name + " - " + quantity + " Qty";

        // Create a ListItem object using the description and
        // product name.
        ListItem item = new ListItem(description, name);

        // Add the ListItem object to the ListBox.
        ProductListBox.Items.Add(item);

        // Use the CommandSource property to retrieve
        // the Add button. Disable the button after
        // the user adds the currently displayed employee
        // name to the ListBox control.
        Button addButton = (Button)e.CommandSource;
        addButton.Enabled = false;
      }

    }

  }

  void ProductFormView_DataBound(Object sender, EventArgs e)
  {

    // To prevent the user from adding duplicate items, 
    // disable the Add button if the item being bound to the 
    // FormView control is already in the ListBox control.

    // Use the Row property to retrieve the data row.
    FormViewRow row = ProductFormView.Row;

    // Retrieve the Add button from the data row.
    Button addButton = (Button)row.FindControl("AddButton");

    // Retrieve the ProductNameLabel control from
    // data row.
    Label productNameLabel = (Label)row.FindControl("ProductNameLabel");

    if (addButton != null && productNameLabel != null)
    {
      // Get the product name from the ProductNameLabel 
      // control.
      string name = productNameLabel.Text;

      // Use the FindByValue method to determine whether
      // the ListBox control already contains an entry for
      // the item.
      ListItem item = ProductListBox.Items.FindByValue(name);

      // Disable the Add button if the ListBox control
      // already contains the item.
      if (item != null)
      {
        addButton.Enabled = false;
      }
      else
      {
        addButton.Enabled = true;
      }
    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>FormViewCommandEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>FormViewCommandEventArgs Example</h3>

      <asp:formview id="ProductFormView"
        datasourceid="ProductSource"
        allowpaging="true"
        datakeynames="ProductID"
        onitemcommand="ProductFormView_ItemCommand"
        ondatabound="ProductFormView_DataBound"  
        runat="server">

        <itemtemplate>

          <table>
            <tr>
              <td style="width:400px">
                <b>Description:</b>
                <asp:label id="ProductNameLabel"
                  text='<%# Eval("ProductName") %>'
                  runat='server'/>
                <br/>      
                <b>Price:</b>
                <asp:label id="PriceLabel"
                  text='<%# Eval("UnitPrice", "{0:c}") %>'
                  runat='server'/>
                <br/>  
                <asp:textbox id="QuantityTextBox"
                  width="50px"
                  maxlength="3" 
                  runat="server"/> Qty                   
              </td>
            </tr>
            <tr>
              <td>
                <asp:requiredfieldvalidator ID="QuantityRequiredValidator"
                  controltovalidate="QuantityTextBox"
                  text="Please enter a quantity."
                  display="Static"
                  runat="server"/>
                <br/>
                <asp:CompareValidator id="QuantityCompareValidator"
                  controltovalidate="QuantityTextBox"
                  text="Please enter an integer value."
                  display="Static"
                  type="Integer"
                  operator="DataTypeCheck"  
                  runat="server"/>    
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <asp:button id="AddButton"
                  text="Add"
                  commandname="Add"
                  runat="server"/>
              </td>
            </tr>
          </table>

        </itemtemplate>

      </asp:formview>

      <br/><br/><hr/>

      Items:<br/>
      <asp:listbox id="ProductListBox"
        runat="server"/>

      <!-- 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="ProductSource"
        selectcommand="Select [ProductID], [ProductName], [UnitPrice] From [Products]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>

    </form>
  </body>
</html>



.NET Framework

4.5, 4, 3.5, 3.0, 2.0에서 지원

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008(서버 코어 역할은 지원되지 않음), Windows Server 2008 R2(서버 코어 역할은 SP1 이상에서 지원, Itanium은 지원되지 않음)

.NET Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.
이 형식의 모든 공용 static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
이 정보가 도움이 되었습니까?
(1500자 남음)

커뮤니티 추가 항목

추가
Microsoft는 MSDN 웹 사이트에 대한 귀하의 의견을 이해하기 위해 온라인 설문 조사를 진행하고 있습니다. 참여하도록 선택하시면 MSDN 웹 사이트에서 나가실 때 온라인 설문 조사가 표시됩니다.

참여하시겠습니까?
© 2013 Microsoft. All rights reserved.