2016-10-04 5 views
0

그리드 뷰를 처음 사용하는 경우 그리드 뷰 형식 SQL 데이터 소스에서 일부 파일 이름을 얻었습니다. 그리고 해당 행을 삭제하면 실제 파일도 삭제됩니다. 다른 폴더에 존재하는 삭제해야합니다. 이는 ..그리드 뷰 행이 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

는 Ans By의

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는 자동 생성 된 삭제 버튼을 가지고 있으므로 Delete 쿼리를 작성하지 않아도됩니다. 경로 위의 정확한 파일 양식을 삭제하고 싶습니다. –