开发者

unable to delete data using gridview

开发者 https://www.devze.com 2023-02-27 10:38 出处:网络
I am building a document uploader web system using asp.net 4.0 . I am stuck in gridview. I can delete the data from gridview. The data gets deleted in the sql table, but 开发者_Python百科the document,

I am building a document uploader web system using asp.net 4.0 . I am stuck in gridview. I can delete the data from gridview. The data gets deleted in the sql table, but 开发者_Python百科the document, which is stored in my folder remains.

I want the document to get deleted when user clicks delete in gridview..is it possible..have been working days on this..

Thanks in advance.


There is a RowDeleted event of gridview which is fired after the deletion of a row, you have to write logic in this event. like...

protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
    if (System.IO.File.Exists("DocumentPath"))
    {
        System.IO.File.Delete("DocumentPath");
    }
}


You can simply call the following line at the end of your GridView's OnRowDeleting event:

if (System.IO.File.Exists("PathToYourDoc")) { System.IO.File.Delete("PathToYourDoc"); }

About how to find a document path, you can visit the following link to see different examples:

http://www.dotnetperls.com/path

0

精彩评论

暂无评论...
验证码 换一张
取 消