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

DetailsView.ItemUpdated Evento

Occurs when an Update button within a DetailsView control is clicked, but after the update operation.

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

public event DetailsViewUpdatedEventHandler ItemUpdated

The ItemUpdated event is raised when an Update button within the DetailsView control is clicked, but after the update operation.Isso permite que você forneça um manipulador de eventos que executa um Personalizar de rotina, como verificar os resultados da operação de Atualizar, sempre que esse evento ocorre.

A DetailsViewUpdatedEventArgs object is passed to the event handler, which allows you to determine the number of rows affected and any exceptions that might have occurred.You can also indicate whether the exception was handled in the event handler by setting the ExceptionHandled property.To keep the control in edit mode after an update operation, set the KeepInEditMode property to true.

Para obter mais informações sobre tratamento de eventos, consulte Consumindo Eventos.

The following code example demonstrates how to use the ItemUpdated event to refresh a GridView control after a DetailsView control performs an update operation.This keeps the GridView control synchronized with the DetailsView control.


<%@ Page Language= %>

<!DOCTYPE html PUBLIC "-
    "http:
<script runat=>
   CustomerDetail_ItemInserted(object sender, 
    DetailsViewInsertedEventArgs e)
  {
    
    
    CustomersView.DataBind();
  }

   CustomerDetail_ItemInserting(object sender, 
    DetailsViewInsertEventArgs e)
  {
    
    
    
     ( i = 0; i < e.Values.Count; i++)
    {
       (e.Values[i] != )
      {
        e.Values[i] = Server.HtmlEncode(e.Values[i].ToString());
      }
    }
  }

   CustomerDetail_ItemUpdated(object sender, 
    DetailsViewUpdatedEventArgs e)
  {
    
    
    CustomersView.DataBind();
  }

   CustomerDetail_ItemUpdating(object sender, 
    DetailsViewUpdateEventArgs e)
  {
    
    
    
     ( i = 0; i < e.NewValues.Count; i++)
    {
       (e.NewValues[i] != )
      {
        e.NewValues[i] = Server.HtmlEncode(e.NewValues[i].ToString());
      }
    }
  }

   CustomerDetail_ItemDeleted(object sender, 
    DetailsViewDeletedEventArgs e)
  {
    
    
    CustomersView.DataBind();
  }
</script>

<html xmlns="http:
<head runat=>
    <title>
      DetailsView Example</title>
</head>
<body>
  <form id= runat=>
    <h3>
      DetailsView Example</h3>
    <table cellspacing=>
      <tr>
        <td>
          <!-- Use a GridView control  combination with      -->
          <!-- a DetailsView control to display master-detail  -->
          <!-- information. When the user selects a store  -->
          <!-- GridView control, the customers
          <!-- information  displayed  the DetailsView     -->
          <!-- control.                                        -->
          <asp:GridView ID= DataSourceID= 
            AutoGenerateColumns=
            DataKeyNames= runat=>
            <HeaderStyle BackColor= ForeColor= />
            <Columns>
              <asp:CommandField ShowSelectButton= />
              <asp:BoundField DataField= 
                HeaderText= />
              <asp:BoundField DataField= 
                HeaderText= />
            </Columns>
          </asp:GridView>
        </td>
        <td valign=>
          <asp:DetailsView ID= 
            DataSourceID= AutoGenerateRows=
            AutoGenerateInsertButton= 
            AutoGenerateEditButton= 
            AutoGenerateDeleteButton=
            EmptyDataText= 
            DataKeyNames= GridLines= 
            OnItemInserted=
            OnItemInserting= 
            OnItemUpdated=
            OnItemUpdating= 
            OnItemDeleted=
            runat=>
            <HeaderStyle BackColor= ForeColor= />
            <RowStyle BackColor= />
            <AlternatingRowStyle BackColor= />
            <EditRowStyle BackColor= />
            <Fields>
              <asp:BoundField DataField= HeaderText= ReadOnly= />
              <asp:BoundField DataField= HeaderText= />
              <asp:BoundField DataField= HeaderText= />
              <asp:BoundField DataField= HeaderText= />
              <asp:BoundField DataField= HeaderText= />
              <asp:BoundField DataField= HeaderText= />
              <asp:BoundField DataField= HeaderText= />
              <asp:BoundField DataField= HeaderText= />
              <asp:BoundField DataField= HeaderText= />
              <asp:BoundField DataField= HeaderText= />
              <asp:BoundField DataField= HeaderText= />
            </Fields>
          </asp:DetailsView>
        </td>
      </tr>
    </table>
    <!-- This example uses Microsoft SQL Server and connects -->
    <!-- to the Northwind sample database.                   -->
    <!-- It  strongly recommended that each data-bound     -->
    <!-- control uses a separate data source control.        -->
    <asp:SqlDataSource ID= runat= 
      ConnectionString=
        
      SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID] 
        FROM [Customers]">
    </asp:SqlDataSource>
    <!-- Add a filter to the data source control  the     -->
    <!-- DetailsView control to display the details of the   -->
    <!-- store selected  the GridView control.             -->
    <asp:SqlDataSource ID= 
      ConnectionString=
        
      runat= 
      SelectCommand="SELECT * FROM [Customers] 
        WHERE ([CustomerID] = @CustomerID)"
      DeleteCommand="DELETE FROM [Customers] 
        WHERE [CustomerID] = @CustomerID"
      InsertCommand="INSERT INTO [Customers] ([CustomerID], 
        [CompanyName], [ContactName], [ContactTitle], [Address], 
        [City], [Region], [PostalCode], [Country], [Phone], [Fax]) 
        VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle, 
        @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax)"
      UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, 
        [ContactName] = @ContactName, [ContactTitle] = @ContactTitle, 
        [Address] = @Address, [City] = @City, [Region] = @Region, 
        [PostalCode] = @PostalCode, [Country] = @Country, 
        [Phone] = @Phone, [Fax] = @Fax 
        WHERE [CustomerID] = @CustomerID">
      <SelectParameters>
        <asp:ControlParameter ControlID= 
          Name= PropertyName=
          Type= />
      </SelectParameters>
      <DeleteParameters>
        <asp:Parameter Name= Type= />
      </DeleteParameters>
      <UpdateParameters>
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
      </UpdateParameters>
      <InsertParameters>
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
        <asp:Parameter Name= Type= />
      </InsertParameters>
    </asp:SqlDataSource>
  </form>
</body>
</html>


Contribuições da comunidade

ADICIONAR
Mostrar:
© 2014 Microsoft