Exportar (0) Imprimir
Expandir Tudo
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original

DataListCommandEventArgs Classe

Provides data for the CancelCommand, DeleteCommand, EditCommand, ItemCommand, and UpdateCommand events of the DataList control. Esta classe não pode ser herdada.

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

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class DataListCommandEventArgs : CommandEventArgs

The CancelCommand event is raised when the Cancel button for an item in the DataList control is clicked.

The DeleteCommand event is raised when the Delete button for an item in the DataList control is clicked.

The EditCommand event is raised when the Edit button for an item in the DataList control is clicked.

The ItemCommand event is raised when any button for an item in the DataList control is clicked.Isso lhe programaticamente testar para quando um botão de comando específica é clicado e ação apropriada.This event is commonly used to handle custom command buttons for the DataList control.

The UpdateCommand event is raised when the Update button for an item in the DataList control is clicked.

For a list of initial property values for an instance of DataListCommandEventArgs, see the DataListCommandEventArgs constructor.

For more information about handling events, see Consumindo Eventos.

TopicLocation
Como: Personalizar itens DataList at Time Rundv_aspnetcon
Como: Personalizar itens da DataList em time de execuçãoBuilding ASP .NET Web Applications in Visual Studio
Como: Personalizar itens da DataList em time de execuçãoBuilding ASP .NET Web Applications in Visual Studio

The following example demonstrates how to define event handlers for the EditCommand, UpdateCommand, CancelCommand and DeleteCommand events of a DataList control.This example specifies the event handlers declaratively, setting the event handler for each command property of the DataList control.


<%@ Page Language= AutoEventWireup= %>
<%@ Import Namespace= %>

<!DOCTYPE html PUBLIC "-
    "http:
<html xmlns="http:
<head>
    <title>DataList Edit Example</title>
<script runat=>

      
      
      DataTable Cart =  DataTable();
      DataView CartView;   

       Page_Load(Object sender, EventArgs e) 
      {

         
         
         
         
         GetSource();

         
         
         
          (!IsPostBack)
         {

            BindList();

         }

      }

       BindList() 
      {

         
         ItemsList.DataSource = CartView;
         ItemsList.DataBind();

      }

       GetSource()
      {

         
         
         
          (Session[] == ) 
         {     

            
            DataRow dr;  

            
            Cart.Columns.Add( DataColumn(, (Int32)));
            Cart.Columns.Add( DataColumn(, (String)));
            Cart.Columns.Add( DataColumn(, (Double)));

            
            
            Session[] = Cart;

            
             ( i = 1; i <= 9; i++) 
            {
               dr = Cart.NewRow();
                (i % 2 != 0)
               {
                  dr[0] = 2;
               }
               
               {
                  dr[0] = 1;
               }
               dr[1] =  + i.ToString();
               dr[2] = (1.23 * (i + 1));
               Cart.Rows.Add(dr);
            }

         } 

         
         {

            
            Cart = (DataTable)Session[];

         }         

         
         CartView =  DataView(Cart);
         CartView.Sort=;

         ;

      }

       Edit_Command(Object sender, DataListCommandEventArgs e) 
      {

         
         
         
         ItemsList.EditItemIndex = e.Item.ItemIndex;
         BindList();

      }

       Cancel_Command(Object sender, DataListCommandEventArgs e) 
      {

         
         
         ItemsList.EditItemIndex = -1;
         BindList();

      }

       Delete_Command(Object sender, DataListCommandEventArgs e) 
      { 

         
         String item = ((Label)e.Item.FindControl()).Text;

         
         
         CartView.RowFilter =  + item + ;
          (CartView.Count > 0) 
         {
            CartView.Delete(0);
         }
         CartView.RowFilter = ;

         
         
         ItemsList.EditItemIndex = -1;
         BindList();

      }

       Update_Command(Object sender, DataListCommandEventArgs e) 
      {

         
         String item = ((Label)e.Item.FindControl()).Text;
         String qty = ((TextBox)e.Item.FindControl()).Text;
         String price = ((TextBox)e.Item.FindControl()).Text;

         
         
         

         
         
         CartView.RowFilter =  + item + ;
          (CartView.Count > 0)
         {
            CartView.Delete(0);
         }
         CartView.RowFilter = ;

         
         
         
         
         

         
         DataRow dr = Cart.NewRow();
         dr[0] = qty;
         dr[1] = item;
         
         
         (price[0] == '$')
         {
            dr[2] = Convert.ToDouble(price.Substring(1));
         }
         
         {
            dr[2] = Convert.ToDouble(price);
         }
         Cart.Rows.Add(dr);

         
         
         
         ItemsList.EditItemIndex = -1;
         BindList();

      }

   </script>

</head>
<body>

   <form id= runat=>

      <h3>DataList Edit Example</h3>

      Click <b>Edit</b> to edit the values of the item.

      <br /><br />

      <asp:DataList id=
           GridLines=
           RepeatColumns=
           RepeatDirection=
           CellPadding=
           CellSpacing=
           OnEditCommand=
           OnUpdateCommand=
           OnDeleteCommand=
           OnCancelCommand=
           runat=>

         <HeaderStyle BackColor=>
         </HeaderStyle>

         <AlternatingItemStyle BackColor=>
         </AlternatingItemStyle>

         <EditItemStyle BackColor=>
         </EditItemStyle>

         <HeaderTemplate>

            Items

         </HeaderTemplate>

         <ItemTemplate>

            Item:
            <%# DataBinder.Eval(Container.DataItem, ) %> 

            <br />

            Quantity:
            <%# DataBinder.Eval(Container.DataItem, ) %>

            <br />

            Price:
            <%# DataBinder.Eval(Container.DataItem, , ) %>

            <br />

            <asp:LinkButton id= 
                 Text= 
                 CommandName=
                 runat=/>

         </ItemTemplate>

         <EditItemTemplate>

            Item:
            <asp:Label id= 
                 Text='<%# DataBinder.Eval(Container.DataItem, ) %>' 
                 runat=/>

            <br />

            Quantity:
            <asp:TextBox id= 
                 Text='<%# DataBinder.Eval(Container.DataItem, ) %>' 
                 runat=/>

            <br />

            Price:
            <asp:TextBox id= 
                 Text='<%# DataBinder.Eval(Container.DataItem, , ) %>' 
                 runat=/>

            <br />

            <asp:LinkButton id= 
                 Text= 
                 CommandName= 
                 runat=/>

            <asp:LinkButton id= 
                 Text= 
                 CommandName= 
                 runat=/>

            <asp:LinkButton id= 
                 Text= 
                 CommandName= 
                 runat=/>

         </EditItemTemplate>

      </asp:DataList>

   </form>

</body>
</html>



The following example demonstrates how to specify the event handlers and programmatically add them to the events in the Page_Load method.


<%@ Page Language= AutoEventWireup= %>
<%@ Import Namespace= %>

<!DOCTYPE html PUBLIC "-
    "http:
<html xmlns="http:
<head>
    <title>DataList Edit Example</title>
<script runat=>

      
      
      DataTable Cart =  DataTable();
      DataView CartView;   

       Page_Load(Object sender, EventArgs e) 
      {

         
         
         
         
         GetSource();

         
         
         
          (!IsPostBack)
         {

            BindList();

         }

         
         ItemsList.EditCommand += 
              DataListCommandEventHandler(.Edit_Command);
         ItemsList.UpdateCommand += 
              DataListCommandEventHandler(.Update_Command);
         ItemsList.DeleteCommand += 
              DataListCommandEventHandler(.Delete_Command);
         ItemsList.CancelCommand += 
              DataListCommandEventHandler(.Cancel_Command);

      }

       BindList() 
      {

         
         ItemsList.DataSource = CartView;
         ItemsList.DataBind();

      }

       GetSource()
      {

         
         
         
          (Session[] == ) 
         {     

            
            DataRow dr;  

            
            Cart.Columns.Add( DataColumn(, (Int32)));
            Cart.Columns.Add( DataColumn(, (String)));
            Cart.Columns.Add( DataColumn(, (Double)));

            
            
            Session[] = Cart;

            
             ( i = 1; i <= 9; i++) 
            {
               dr = Cart.NewRow();
                (i % 2 != 0)
               {
                  dr[0] = 2;
               }
               
               {
                  dr[0] = 1;
               }
               dr[1] =  + i.ToString();
               dr[2] = (1.23 * (i + 1));
               Cart.Rows.Add(dr);
            }

         } 

         
         {

            
            Cart = (DataTable)Session[];

         }         

         
         CartView =  DataView(Cart);
         CartView.Sort=;

         ;

      }

       Edit_Command(Object sender, DataListCommandEventArgs e) 
      {

         
         
         
         ItemsList.EditItemIndex = e.Item.ItemIndex;
         BindList();

      }

       Cancel_Command(Object sender, DataListCommandEventArgs e) 
      {

         
         
         ItemsList.EditItemIndex = -1;
         BindList();

      }

       Delete_Command(Object sender, DataListCommandEventArgs e) 
      { 

         
         String item = ((Label)e.Item.FindControl()).Text;

         
         
         CartView.RowFilter =  + item + ;
          (CartView.Count > 0) 
         {
            CartView.Delete(0);
         }
         CartView.RowFilter = ;

         
         
         ItemsList.EditItemIndex = -1;
         BindList();

      }

       Update_Command(Object sender, DataListCommandEventArgs e) 
      {

         
         String item = ((Label)e.Item.FindControl()).Text;
         String qty = ((TextBox)e.Item.FindControl()).Text;
         String price = ((TextBox)e.Item.FindControl()).Text;

         
         
         

         
         
         CartView.RowFilter =  + item + ;
          (CartView.Count > 0)
         {
            CartView.Delete(0);
         }
         CartView.RowFilter = ;

         
         
         
         
         

         
         DataRow dr = Cart.NewRow();
         dr[0] = qty;
         dr[1] = item;
         
         
         (price[0] == '$')
         {
            dr[2] = Convert.ToDouble(price.Substring(1));
         }
         
         {
            dr[2] = Convert.ToDouble(price);
         }
         Cart.Rows.Add(dr);

         
         
         
         ItemsList.EditItemIndex = -1;
         BindList();

      }

   </script>

</head>
<body>

   <form id= runat=>

      <h3>DataList Edit Example</h3>

      Click <b>Edit</b> to edit the values of the item.

      <br /><br />

      <asp:DataList id=
           GridLines=
           RepeatColumns=
           RepeatDirection=
           CellPadding=
           CellSpacing=
           runat=>

         <HeaderStyle BackColor=>
         </HeaderStyle>

         <AlternatingItemStyle BackColor=>
         </AlternatingItemStyle>

         <EditItemStyle BackColor=>
         </EditItemStyle>

         <HeaderTemplate>

            Items

         </HeaderTemplate>

         <ItemTemplate>

            Item:
            <%# DataBinder.Eval(Container.DataItem, ) %> 

            <br />

            Quantity:
            <%# DataBinder.Eval(Container.DataItem, ) %>

            <br />

            Price:
            <%# DataBinder.Eval(Container.DataItem, , ) %>

            <br />

            <asp:LinkButton id= 
                 Text= 
                 CommandName=
                 runat=/>

         </ItemTemplate>

         <EditItemTemplate>

            Item:
            <asp:Label id= 
                 Text='<%# DataBinder.Eval(Container.DataItem, ) %>' 
                 runat=/>

            <br />

            Quantity:
            <asp:TextBox id= 
                 Text='<%# DataBinder.Eval(Container.DataItem, ) %>' 
                 runat=/>

            <br />

            Price:
            <asp:TextBox id= 
                 Text='<%# DataBinder.Eval(Container.DataItem, , ) %>' 
                 runat=/>

            <br />

            <asp:LinkButton id= 
                 Text= 
                 CommandName= 
                 runat=/>

            <asp:LinkButton id= 
                 Text= 
                 CommandName= 
                 runat=/>

            <asp:LinkButton id= 
                 Text= 
                 CommandName= 
                 runat=/>

         </EditItemTemplate>

      </asp:DataList>

   </form>

</body>
</html>



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

Quaisquer membros públicos estático (compartilhados na Visual Basic) desse tipo são Thread seguro. Não há garantia de que qualquer membro de instância seja isento de segmentos.

Contribuições da comunidade

ADICIONAR
Mostrar:
© 2015 Microsoft