ButtonColumn.CommandName 속성

정의

ButtonColumn 개체의 단추를 클릭할 때 수행할 명령을 나타내는 문자열을 가져오거나 설정합니다.

public:
 virtual property System::String ^ CommandName { System::String ^ get(); void set(System::String ^ value); };
public virtual string CommandName { get; set; }
member this.CommandName : string with get, set
Public Overridable Property CommandName As String

속성 값

ButtonColumn에 있는 단추를 클릭할 때 수행할 명령을 나타내는 문자열입니다. 기본값은 빈 문자열("")입니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 CommandName 단추를 사용 하 여 명령 이름을 연결 하는 속성입니다. 그런 다음 클릭 한 단추의 명령 이름에 대 한 이벤트 처리기에서 프로그래밍 방식으로 결정 됩니다는 ItemCommand 이벤트 및 적절 한 조치를 수행 합니다.


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

    protected void Page_Init(object sender, EventArgs e)
    {
       // Create dynamic column to add to Columns collection.
       ButtonColumn AddColumn = new ButtonColumn();
       AddColumn.HeaderText="Add Item"; 
       AddColumn.Text="Add";
       AddColumn.CommandName="Add";
       AddColumn.ButtonType = ButtonColumnType.PushButton;

       // Add column to Columns collection.
       ItemsGrid.Columns.AddAt(0, AddColumn);
    }


    protected void ItemsGrid_ItemCommand(object source, DataGridCommandEventArgs e)
    {
        if (e.CommandName == "Add")
        {
            // Add logic for addition operation here.
            this.TextBox1.Text = "Added";
        }

    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Untitled Page</title>
  </head>
  <body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" /><br />
        <asp:DataGrid 
          ID="ItemsGrid" 
          runat="server" 
          DataSourceID="CustomersSqlDataSource" 
          AutoGenerateColumns="true" 
          OnItemCommand="ItemsGrid_ItemCommand" />
        
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Northwind sample database.                   -->
        <asp:sqldatasource id="CustomersSqlDataSource"  
          selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]"
          connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
          runat="server">
        </asp:sqldatasource>

    </div>
    </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">
<script runat="server">

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
        ' Create dynamic column to add to Columns collection.
        Dim AddColumn As New ButtonColumn
        AddColumn.HeaderText = "Add Item"
        AddColumn.Text = "Add"
        AddColumn.CommandName = "Add"
        AddColumn.ButtonType = ButtonColumnType.PushButton

        ' Add column to Columns collection.
        ItemsGrid.Columns.AddAt(0, AddColumn)
    End Sub


    Protected Sub ItemsGrid_ItemCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs)
        If e.CommandName = "Add" Then
            ' Add logic for addition operation here.
            TextBox1.Text = "Added"          
        End If
    End Sub
    
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="head1" runat="server">
    <title>Untitled Page</title>
  </head>
  <body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" /><br />
        <asp:DataGrid 
          ID="ItemsGrid" 
          runat="server" 
          DataSourceID="CustomersSqlDataSource" 
          AutoGenerateColumns="true" 
          OnItemCommand="ItemsGrid_ItemCommand" />
        
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Northwind sample database.                   -->
        <asp:sqldatasource id="CustomersSqlDataSource"  
          selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]"
          connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
          runat="server">
        </asp:sqldatasource>

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

설명

사용 된 CommandName 와 같은 명령 이름을 연결할 속성을 Add 또는 Remove, 단추를 사용 하 여 합니다. 설정할 수 있습니다 합니다 CommandName 속성에 있는 단추 수행할 동작을 식별 하는 모든 문자열을는 System.Web.UI.WebControls.ButtonColumn 개체를 클릭 합니다. 다음을 확인할 수 있습니다 프로그래밍 방식으로 이벤트의 이벤트 처리기에서 명령 이름을 ItemCommand 이벤트 하 고 적절 한 조치를 수행 합니다.

이 속성의 값은 뷰 상태에 저장 됩니다.

적용 대상

추가 정보