This article was translated by machine. To view in the article in English, select the English check box. You can also display the English text in a popup window by moving the mouse pointer over the text.
الترجمة
الأصلي
This documentation is archived and is not being maintained.

DetailsViewDeletedEventHandler مفوَّض

Visual Studio 2010

تمثل الطريقة التي يعالج ItemDeletedحدث من DetailsViewعنصر تحكم.

مساحة الاسم:  System.Web.UI.WebControls
التجميع:  System.Web (في System.Web.dll)

public delegate void DetailsViewDeletedEventHandler(
	Object sender,
	DetailsViewDeletedEventArgs e
)

المعلمات

sender
النوع: System.Object
مصدر الحدث.
e
النوع: System.Web.UI.WebControls.DetailsViewDeletedEventArgs
DetailsViewDeletedEventArgs يحتوي على بيانات حدث.

DetailsView التحكم raهوes ItemDeletedحدث عند يحذف زر (زر مع به CommandNameتعيين خاصية إلى "يحذف") داخل عنصر التحكم هو النقر فوقه، ولكن بعد DetailsViewبيحذف عنصر التحكم في السجل. المعلمات التي يتم استخدامها لإنشاء بند الموقع.

عندما تقوم بإنشاء DetailsViewDeletedEventHandlerتفويض، تتعرف على الطريقة التي سيقوم بمعالجة حدث. لربط حدث مع معالج الأحداث الخاص بك، قم بإضافة مثيل تفويض للحدث. يتم استدعاء معالج حدث عند حدوث حدث، إلا إذا قمت بإزالة المفوض. للحصول على مزيد من المعلومات حول حدث-المفوضون معالج، راجع أحداث و مفوضون.

ما يلي تعليمات برمجية مثال يوضح كيفية إضافة برمجياً DetailsViewDeletedEventHandlerتفويض ItemDeletedحدث من DetailsViewعنصر التحكم.



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

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

  <script runat="server">

    void Page_Load(Object sender, EventArgs e)
    {

      // Create a new DetailsView object.
      DetailsView customerDetailsView = new DetailsView();

      // Set the DetailsView object's properties.
      customerDetailsView.ID = "CustomerDetailsView";
      customerDetailsView.DataSourceID = "DetailsViewSource";
      customerDetailsView.AutoGenerateRows = true;
      customerDetailsView.AutoGenerateDeleteButton = true;
      customerDetailsView.AllowPaging = true;
      customerDetailsView.PagerSettings.Mode = 
        PagerButtons.NextPrevious;
      customerDetailsView.DataKeyNames = new String[1] { "CustomerID" };

      // Programmatically register the event-handling method
      // for the ItemDeleted event of a DetailsView control.
      customerDetailsView.ItemDeleted += 
        new DetailsViewDeletedEventHandler(
        this.CustomerDetailView_ItemDeleted);

      // Add the DetailsView object to the Controls collection
      // of the PlaceHolder control.
      DetailsViewPlaceHolder.Controls.Add(customerDetailsView);

    }

    void CustomerDetailView_ItemDeleted(Object sender, 
      DetailsViewDeletedEventArgs e)
    {
      // Use the Exception property to determine whether an exception
      // occurred during the delete operation.
      if (e.Exception == null)
      {
        // Use the AffectedRows property to determine the numbers of
        // rows affected by the delete operation.
        if (e.AffectedRows == 1)
        {
          MessageLabel.Text = e.AffectedRows.ToString() 
            + " record deleted successfully.";
        }
        else
        {
          MessageLabel.Text = e.AffectedRows.ToString() 
            + " records deleted successfully.";
        }
      }
      else
      {
        // Insert the code to handle the exception.
        MessageLabel.Text = e.Exception.Message;

        // Use the ExceptionHandled property to indicate that the 
        // exception is already handled.
        e.ExceptionHandled = true;
      }
    }

  </script>

  <head runat="server">
    <title>DetailsViewDeletedEventHandler Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>DetailsViewDeletedEventHandler Example</h3>

        <!-- Use a PlaceHolder control as the container for the -->
        <!-- dynamically generated DetailsView control.         -->       
        <asp:PlaceHolder id="DetailsViewPlaceHolder"
          runat="server"/>

        <br/><br/>

        <asp:label id="MessageLabel"
          forecolor="Red"
          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="DetailsViewSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], 
            [City], [PostalCode], [Country] From [Customers]"
          deletecommand="Delete [Customers] 
            Where [CustomerID]=@CustomerID"
          connectionstring=
            "<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>

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



ما يلي تعليمات برمجية مثال يوضح كيفية إضافة بشكل إلزامي DetailsViewDeletedEventHandlerتفويض ItemDeletedحدث من DetailsViewعنصر التحكم.



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

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

  <script runat="server">

    void CustomerDetailView_ItemDeleted(Object sender, 
      DetailsViewDeletedEventArgs e)
    {
      // Use the Exception property to determine whether an exception
      // occurred during the delete operation.
      if (e.Exception == null)
      {
        // Use the AffectedRows property to determine the numbers of
        // rows affected by the delete operation.
        if (e.AffectedRows == 1)
        {
          MessageLabel.Text = e.AffectedRows.ToString() 
            + " record deleted successfully.";
        }
        else
        {
          MessageLabel.Text = e.AffectedRows.ToString() 
            + " records deleted successfully.";
        }
      }
      else
      {
        // Insert the code to handle the exception.
        MessageLabel.Text = e.Exception.Message;

        // Use the ExceptionHandled property to indicate that the 
        // exception is already handled.
        e.ExceptionHandled = true;
      }
    }

  </script>

  <head runat="server">
    <title>DetailsViewDeletedEventHandler Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>DetailsViewDeletedEventHandler Example</h3>

        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          autogeneraterows="true"
          autogeneratedeletebutton="true"
          allowpaging="true"
          datakeynames="CustomerID" 
          runat="server">

          <pagersettings mode="NextPrevious"/>

        </asp:detailsview>

        <br/><br/>

        <asp:label id="MessageLabel"
          forecolor="Red"
          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="DetailsViewSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], 
            [City], [PostalCode], [Country] From [Customers]"
          deletecommand="Delete [Customers] 
            Where [CustomerID]=@CustomerID"
          connectionstring=
            "<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>

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



نظام التشغيل Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, الإصدار x64 من نظام التشغيل Windows XP Professional, Windows XP Starter Edition, Windows Server 2008, نظام التشغيل Windows Server 2003, نظام التشغيل Windows Server 2000 المزود بحزمة الخدمة SP4, نظام التشغيل Windows Millennium Edition, نظام التشغيل Windows 98

لا يدعم .NET Framework و .NET Compact Framework كافة الإصدارات الخاصة بكل نظام أساسي. للحصول على قائمة بالإصدارات المدعمة، راجع متطلبات النظام إطار عمل .NET.

.NET Framework

مدعوم في: 4, 3.5, 3.0, 2.0
إظهار: