2016-10-04 77 views
0

我是新来的网格视图, 我有一些文件名在网格视图形式Sql数据源,如果我删除该行,物理文件也应该删除某些其他文件夹上存在的内容。 这是我的代码我试过..如何执行物理文件删除操作时gridview行删除使用asp.net

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
     { 
      if(e.Row.RowType==DataControlRowType.DataRow) 
      { 
       Control control=e.Row.Cells[0].Controls[0]; 

       String Filename = e.Row.Cells[2].ToString(); 

       if (control is LinkButton) 
       { 
        ((LinkButton)control).OnClientClick = "return confirm('Are you Sure you want to delete? this Cannot be undone')"; 

       if((File.Exists(Server.MapPath("~/Content/MainContent/BulkDataContent/" + Filename)))) 
        { 
        File.Delete(Server.MapPath("~/Content/MainContent/BulkDataContent/" + Filename)); 
        } 
       } 

但问题是,当我从网格视图中删除一个文件,一排被删除从网格视图和所有的物理文件被删除窗体的文件夹..它循环直到结束.. 帮我解决这个问题... 在此先感谢。

+0

这里是链接按钮单击事件? –

回答

1

更新答

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
     { 
      if(e.Row.RowType==DataControlRowType.DataRow) 
      { 
       Control control=e.Row.Cells[0].Controls[0]; 

       String Filename = e.Row.Cells[2].ToString(); 

       if (control is LinkButton) 
       { 
        ((LinkButton)control).OnClientClick = "return confirm('Are you Sure you want to delete? this Cannot be undone')"; 
    //write here your Delete query/Procedure 


    if((File.Exists(Server.MapPath("~/Content/MainContent/BulkDataContent/" + Filename)))) 
       { 
       File.Delete(Server.MapPath("~/Content/MainContent/BulkDataContent/" + Filename)); 
       } 
      } 
+0

这个GridView有自动生成的删除按钮,所以我认为不需要写删除查询,现在我想删除上面的路径的确切文件窗体,在哪个用户点击 –