FormView.DeleteItem メソッド
アセンブリ: System.Web (system.web.dll 内)


プログラムによって FormView コントロールの現在のレコードをデータ ソースから削除するには、DeleteItem メソッドを使用します。このメソッドは通常、FormView コントロール以外から (ページ上の別のコントロールなどから) 現在のレコードを削除する必要がある場合に使用されます。また、このメソッドを呼び出すと、ItemDeleted イベントと ItemDeleting イベントも発生します。

DeleteItem メソッドを使用して、プログラムによって FormView コントロールの現在のレコードをデータ ソースから削除する方法を次の例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub DeleteButton_Click(ByVal sender As Object, ByVal e As EventArgs) ' Use the DeleteItem method to programmatically delete ' the current record in the FormView control. EmployeeFormView.DeleteItem() End Sub </script> <html> <body> <form runat="server"> <h3>FormView DeleteItem Example</h3> <asp:formview id="EmployeeFormView" datasourceid="EmployeeSource" allowpaging="true" datakeynames="EmployeeID" runat="server"> <itemtemplate> <table> <tr> <td> <asp:image id="EmployeeImage" imageurl='<%# Eval("PhotoPath") %>' alternatetext='<%# Eval("LastName") %>' runat="server"/> </td> <td> <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3> <%# Eval("Title") %> </td> </tr> </table> </itemtemplate> </asp:formview> <hr/> <asp:Button id="DeleteButton" text="Delete Record" onclick="DeleteButton_Click" 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="EmployeeSource" selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]" deletecommand="Delete [Employees] Where [EmployeeID]=@EmployeeID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void DeleteButton_Click(Object sender, EventArgs e) { // Use the DeleteItem method to programmatically delete // the current record in the FormView control. EmployeeFormView.DeleteItem(); } </script> <html> <body> <form runat="server"> <h3>FormView DeleteItem Example</h3> <asp:formview id="EmployeeFormView" datasourceid="EmployeeSource" allowpaging="true" datakeynames="EmployeeID" runat="server"> <itemtemplate> <table> <tr> <td> <asp:image id="EmployeeImage" imageurl='<%# Eval("PhotoPath") %>' alternatetext='<%# Eval("LastName") %>' runat="server"/> </td> <td> <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3> <%# Eval("Title") %> </td> </tr> </table> </itemtemplate> </asp:formview> <hr/> <asp:Button id="DeleteButton" text="Delete Record" onclick="DeleteButton_Click" 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="EmployeeSource" selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]" deletecommand="Delete [Employees] Where [EmployeeID]=@EmployeeID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からFormView.DeleteItem メソッドを検索する場合は、下記のリンクをクリックしてください。

- FormView.DeleteItem メソッドのページへのリンク