Link to home
Start Free TrialLog in
Avatar of MikeCombe
MikeCombeFlag for United States of America

asked on

How to delete a file using a button in GridView

I populated a <asp:GridView ID="GridView1" with a ist of files.
I want to add a "delete" button to the gridview, which when clicked would delete that file.
Avatar of Ess Kay
Ess Kay
Flag of United States of America image

add a column, set the column type to button

example:  http://stackoverflow.com/questions/3062733/gridview-changing-text-in-a-button-column
ASKER CERTIFIED SOLUTION
Avatar of Ess Kay
Ess Kay
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MikeCombe

ASKER

I have the button....just trying to figure out how to pass the specific filename....

<asp:Button OnClick="MyBtnHandler" Text="Delete" CommandArgument="<%# DataBinder.Eval(Container, 'DataItem.Name') %>" CommandName="Delete" name="btnDelete" ID="btnDelete" runat="server" Width="100" />
Here's the gridview code....

<asp:TemplateField headertext="" HeaderStyle-HorizontalAlign="Left">
        <ItemTemplate>
            <asp:Button OnClick="MyBtnHandler" Text="Delete" CommandArgument="<%# DataBinder.Eval(Container, 'DataItem.Name') %>" CommandName="Delete" name="btnDelete" ID="btnDelete" runat="server" Width="100" />                  
        </ItemTemplate>
    </asp:TemplateField>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
actually, it just takes this..

        Imports System.IO

        Dim myFilename as String = "test.jpg"
        Dim myFolder As String = "C:\xxxx\"
        File.Delete(myFolder & myFilename)
Gretchen I could help