削除をクリックすると、イメージを含むレコードがデータベースから削除されますが、イメージはフォルダ内に残ります。どうか経験豊富なasp.netプログラマーが助けてくれますか? ありがとうございます!Gridviewから削除ボタンを使用してデータベースとフォルダからレコードを削除する
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Management.aspx.cs" Inherits="pages_Management_Management" %>
<asp:GridView ID="grdProducts" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="ID,Image" DataSourceID="generalProducts" Width="80%" OnRowEditing="grdProducts_RowEditing" CellPadding="4"
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="CatID" HeaderText="CatID" SortExpression="CatID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="Image" HeaderText="Image" SortExpression="Image" />
<asp:BoundField DataField="Seller" HeaderText="Seller" SortExpression="Seller" />
<asp:BoundField DataField="StateID" HeaderText="StateID" SortExpression="StateID" />
<asp:BoundField DataField="CityID" HeaderText="CityID" SortExpression="CityID" />
<asp:BoundField DataField="StreetID" HeaderText="StreetID" SortExpression="StreetID" />
<asp:BoundField DataField="StreetNoID" HeaderText="StreetNoID" SortExpression="StreetNoID" />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:BoundField DataField="Packaging" HeaderText="Packaging" SortExpression="Packaging" />
<asp:BoundField DataField="Unit" HeaderText="Unit" SortExpression="Unit" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
は " DeleteCommandの=" FROM DELETE新製品を追加[製品] WHERE [ID] = @ID " InsertCommandは=" INSERT INTO [製品]([名前])VALUES(@名) " でSelectCommand = "SELECT * FROM [製品]" にUpdateCommand = "UPDATE [製品] SET [名] = @Name WHERE [ID] = @ID">から
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</p>
<p>
</p>
<p>
<asp:LinkButton ID="LinkButton2" runat="server" CssClass="button" PostBackUrl="~/pages/Management/ManageProductCats.aspx">Add New ProductCat</asp:LinkButton>
</p>
<asp:GridView ID="grdProductsType" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="generalProductCat" Width="50%" style="margin-top: 0px" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="generalProductCat" runat="server" ConnectionString=
"<%$ ConnectionStrings:SuperStoreDBConnectionString %>"
DeleteCommand="DELETE FROM [ProductCat] WHERE [ID] = @ID"
InsertCommand="INSERT INTO [ProductCat] ([Name]) VALUES (@Name)"
SelectCommand="SELECT * FROM [ProductCat]"
UpdateCommand="UPDATE [ProductCat] SET [Name] = @Name WHERE [ID] = @ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
を削除するためのC#でメソッドを作成する必要があります@ MMoore94、私はあなたの貢献を感謝し、エラーを投げたonDeleteイベント。また、DBには多くの画像があり、Idは削除する特定の画像を指します。あなたは以下の私のメソッドで間違っていると思いますか?protected void grdProducts_RowDeleting(Object sender、GridViewEditEventArgs e){GridViewRow row = grdProducts.Rows [e.NewEditIndex]; int rowId = Convert.ToInt32(row.Cells [1] .Text); File.Delete( "〜/ Images/Products /" + rowId); } –