【问题标题】:unable to delete data using gridview无法使用gridview删除数据
【发布时间】:2011-04-21 16:50:05
【问题描述】:

我正在使用 asp.net 4.0 构建一个文档上传器网络系统。 我被困在gridview中。我可以从gridview中删除数据。数据在 sql 表中被删除,但 存储在我的文件夹中的文档 仍然存在。

我希望当用户在 gridview 中单击删除时删除该文档..这可能吗..已经有工作日了..

提前致谢。

【问题讨论】:

    标签: asp.net sql file gridview document


    【解决方案1】:

    gridview 有一个RowDeleted 事件在删除一行后触发,你必须在这个事件中编写逻辑。喜欢...

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

    【讨论】:

      【解决方案2】:

      您可以在 GridView 的 OnRowDeleting 事件结束时简单地调用以下行:

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

      关于如何查找文档路径,您可以访问以下链接查看不同的示例:

      http://www.dotnetperls.com/path

      【讨论】:

      • protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { } protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e) { if (System.IO.File.Exists(Path.GetFileName(docPath))); { System.IO.File.Delete(Path.GetFileName(docPath)); } } protected void GridView1_RowDatabound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { } }
      • 上面的代码是我正在尝试的,..同样的问题仍然存在,..如果我做错了什么,我很抱歉,我对 asp.net 还是很陌生..@Muhammad @ncakmak
      猜你喜欢
      • 1970-01-01
      • 2021-05-15
      • 1970-01-01
      • 2016-01-30
      • 2017-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多