Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

DetailsViewCommandEventHandler Representante

Represents the method that handles the ItemCommand event of a DetailsView control.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (em System.Web. dll)

public delegate void DetailsViewCommandEventHandler(
	Object sender,
	DetailsViewCommandEventArgs e
)

Parâmetros

sender
Tipo: System.Object

A origem do evento.

e
Tipo: System.Web.UI.WebControls.DetailsViewCommandEventArgs

A DetailsViewCommandEventArgs that contains the event data.

The DetailsView control raises the ItemCommand event when a button within a ButtonField, CommandField, or TemplateField row field is clicked.Isso permite que você forneça um manipulador de eventos que executa um Personalizar de rotina sempre que esse evento ocorre.

Observação:

The DetailsView control also raises other specialized events when certain buttons are clicked (buttons with the CommandName property set to "Delete", "Insert", "Page", or "Update").When using one of these buttons, you should consider using one of the specialized events provided by the control (such as ItemDeleted or ItemDeleting).

When you create a DetailsViewCommandEventHandler delegate, you identify the method that will handle the event.Para associar o evento com o manipulador de eventos, adicione uma instância do delegate ao evento.O manipulador de evento é chamado sempre que o evento ocorre, a menos que você remova o delegate.Para obter mais informações sobre delegates de manipulador de eventos, consulte Eventos e representantes.

The following code example demonstrates how to programmatically add a DetailsViewCommandEventHandler delegate to the ItemCommand event of a DetailsView control.Este exemplo usa o modelo de codificação de Arquivo Simples.


<%@ page language= %>

<!DOCTYPE html PUBLIC "-
    "http:
<script runat=>

   Page_Load(Object sender, EventArgs e)
  {

    
    DetailsView customerDetailsView =  DetailsView();

    
    customerDetailsView.ID = ;
    customerDetailsView.DataSourceID = ;
    customerDetailsView.AutoGenerateRows = ;
    customerDetailsView.AllowPaging = ;
    customerDetailsView.DataKeyNames =  String[1] {  };

    
    ButtonField field =  ButtonField();
    field.ButtonType = ButtonType.Link;
    field.CausesValidation = ;
    field.Text = ;
    field.CommandName=;

    customerDetailsView.Fields.Add(field);

    
    
    customerDetailsView.ItemCommand 
      +=  DetailsViewCommandEventHandler( 
      .CustomerDetailsView_ItemCommand);

    
    
    DetailsViewPlaceHolder.Controls.Add(customerDetailsView);

  }

   CustomerDetailsView_ItemCommand(Object sender, 
    DetailsViewCommandEventArgs e)
  {

    
    
     (e.CommandName == )
    {
      
      DetailsView customerDetailsView = (DetailsView)e.CommandSource;

      

      
      
      
      DetailsViewRow row = customerDetailsView.Rows[1];

      
      
      
      String name = row.Cells[1].Text;

      
      ListItem item =  ListItem(name);

      
      
       (!CustomerListBox.Items.Contains(item))
      {
        CustomerListBox.Items.Add(item);
      }

    }

  }

</script>

<html xmlns="http:
  <head runat=>
    <title>DetailsViewCommandEventHandler Example</title>
</head>
<body>
    <form id= runat=>

      <h3>DetailsViewCommandEventHandler Example</h3>

      <!-- Use a PlaceHolder control  the container  the -->
      <!-- dynamically generated DetailsView control.         -->       
      <asp:placeholder id=
        runat=/>

      <br/><br/>

      Selected Customers:<br/>
      <asp:listbox id=
        runat=/>

      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!--  the web.config file.                            -->
      <asp:sqldatasource id=
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        connectionstring=
             

        runat=/>  

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


O exemplo de código a seguir mostra uma versão de modelo de codificação code-behind do exemplo anterior.Para esse exemplo funcione, você deve copiar o código a seguir para o arquivo code-behind associado.

<%@ Page Language= AutoEventWireup=  CodeFile= Inherits= %>

<!DOCTYPE html PUBLIC "-
    "http:
<html xmlns="http:
  <head runat=>
    <title>DetailsViewCommandEventHandler Example</title>
</head>
<body>
    <form id= runat=>

      <h3>DetailsViewCommandEventHandler Example</h3>

      <!-- Use a PlaceHolder control  the container  the -->
      <!-- dynamically generated DetailsView control.         -->       
      <asp:placeholder id=
        runat=/>

      <br/><br/>

      Selected Customers:<br/>
      <asp:listbox id=
        runat=/>

      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!--  the web.config file.                            -->
      <asp:sqldatasource id=
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        connectionstring="
          <%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat=/>  

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


O exemplo de código a seguir mostra o arquivo code-behind para o exemplo anterior.

 System;
 System.Data;
 System.Configuration;
 System.Web;
 System.Web.Security;
 System.Web.UI;
 System.Web.UI.WebControls;
 System.Web.UI.WebControls.WebParts;
 System.Web.UI.HtmlControls;

 partial  _Default : System.Web.UI.Page 
{
      Page_Load(object sender, EventArgs e)
    {
        
        DetailsView customerDetailsView =  DetailsView();

        
        customerDetailsView.ID = ;
        customerDetailsView.DataSourceID = ;
        customerDetailsView.AutoGenerateRows = ;
        customerDetailsView.AllowPaging = ;
        customerDetailsView.DataKeyNames =  String[1] {  };

        
        ButtonField field =  ButtonField();
        field.ButtonType = ButtonType.Link;
        field.CausesValidation = ;
        field.Text = ;
        field.CommandName = ;

        customerDetailsView.Fields.Add(field);

        
        
        customerDetailsView.ItemCommand +=  DetailsViewCommandEventHandler(.CustomerDetailsView_ItemCommand);

        
        
        DetailsViewPlaceHolder.Controls.Add(customerDetailsView);
    }

     CustomerDetailsView_ItemCommand(Object sender, DetailsViewCommandEventArgs e)
    {

        
        
         (e.CommandName == )
        {
            
            DetailsView customerDetailsView = (DetailsView)sender;

            

            
            
            
            DetailsViewRow row = customerDetailsView.Rows[1];

            
            
            
            String name = row.Cells[1].Text;

            
            ListItem item =  ListItem(name);

            
            
             (!CustomerListBox.Items.Contains(item))
            {
                CustomerListBox.Items.Add(item);
            }

        }

    }
}


The following code example demonstrates how to declaratively add a DetailsViewCommandEventHandler delegate to the ItemCommand event of a DetailsView control.


<%@ Page Language= %>

<!DOCTYPE html PUBLIC "-
    "http:
<script runat=>

     CustomerDetailView_ItemCommand(Object sender, DetailsViewCommandEventArgs e)
    {

        
        
         (e.CommandName == )
        {

            

            
            
            
            DetailsViewRow row = CustomerDetailView.Rows[1];

            
            
            
            String name = row.Cells[1].Text;

            
            ListItem item =  ListItem(name);

            
            
             (!ContactListBox.Items.Contains(item))
            {
                ContactListBox.Items.Add(item);
            }

        }

    }

</script>

<html xmlns="http:
<head runat=>
    <title>
            DetailsView ItemCommand Example</title>
</head>
<body>
    <form id= runat=>
        <h3>
            DetailsView ItemCommand Example</h3>
        <asp:DetailsView ID= 
            DataSourceID=
            AutoGenerateRows= 
            DataKeyNames= 
            AllowPaging= 
            OnItemCommand=
            runat=>

            <FieldHeaderStyle BackColor= ForeColor= />

            <Fields>
                <asp:BoundField DataField= HeaderText= />
                <asp:BoundField DataField= HeaderText= />
                <asp:BoundField DataField= HeaderText= />
                <asp:ButtonField CommandName= Text= />
            </Fields>
        </asp:DetailsView>

        <hr />

        Contacts:<br />
        <asp:ListBox ID= runat= />
        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value   -->
        <!--  the web.config file.                            -->
        <asp:SqlDataSource ID= runat= 
          ConnectionString=
            
            InsertCommand=
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </asp:SqlDataSource>
    </form>
</body>
</html>


Contribuições da comunidade

ADICIONAR
Mostrar: