2009-11-09 5 views
0

비디오 업로드 및 재생을위한 웹 응용 프로그램이 있습니다. 관리자가 업로드 할 수 있으며 사용자가 업로드 된 파일을 볼 수 있습니다. 데이터베이스의 링크가 자동으로 중계기로 채워집니다. 내 대상은 관리자가 업로드 된 파일을 삭제할 수 있습니다. . 파일 또한 database.I에서 삭제 SQl experess 및 VS2005 사용하고 있습니다. 어떻게 이럴 수 있습니까?리피터에서 삭제

답변

7

원하는 단추 나 다른 컨트롤을 놓고이 단추에 command name 속성이 "delete"와 같게 설정하면 명령 인수 속성에 id를 입력하여 삭제할 행을 알 수 있고 중계기 ItemCommand 이벤트에서이 명령 이름을 확인한 다음 삭제 기능을 수행하십시오.

예 :

<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand"> 
    <ItemTemplate> 
     <asp:LinkButton ID="LinkButton1" CommandName="Delete" OnClientClick="javascript:if(!confirm('Delete this information? this will delete permanently'))return false;" CommandArgument='<%#Eval("EntityID") %>' runat="server">Delete</asp:LinkButton> 
    </ItemTemplate> 
</asp:Repeater> 

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) 
{ 
    if (e.CommandName == "Delete" && e.CommandArgument.ToString() != "") 
    { 
     // DoDelete then rebind 
    } 
} 

코드 이런 식으로 뭔가있을 것입니다 삭제 : 다음 당신이 (.. JQuery와 대화, bootboxjs 등 같은) u'd 사용자 정의 확인을 사용하려는 경우

Dim connectionString As String = ConfigurationManager.ConnectionStrings("UploadConnectionString").ConnectionString 

Dim adapter As New SqlDataAdapter("DELETE FROM FileM where id=" & e.CommandArgument.ToString(), connectionString) 
+0

삭제할 코드는 무엇입니까? – user85511

+0

당신은 순수한 ADO.Net을 사용하고 있습니까? 연결되었거나 연결이 끊어 졌습니까? 또는 ORM을 사용 하시겠습니까? –

+0

나는이 희미한 ConnectionString을 같이 사용하고 있습니다로 문자열 = ConfigurationManager.ConnectionStrings ("UploadConnectionString"). – user85511

0

버튼의 "포스트 백 문자열"을 생성하거나 어떻게 든 그것을 얻을 수 있습니다. asp.net은 페이지 렌더링 후 포스트 백 이름을 제공합니다. __doPostBack ('ctl00 $ ContentPlaceHolder1 $ btnDeleteSelected',) '. 이것을 깨닫고 나서 js 함수를 작성했습니다.이 함수는 버튼의 포스트 백 str을 생성합니다.

function PostBackBtnMake(id) { // id : ContentPlaceHolder1_btnDeleteSelected 
    var result; 
    var temp = id.split('_'); 
    result = 'ctl00$' + temp[0] + '$' + temp[1]; 
    return result; 
} 

그러면 사용자 정의 확인 상자에서 사용할 수 있습니다 (이 경우에는 bootboxjs를 사용했습니다).

function PostBackBtn(e) { 
    var _result = false; 
    bootbox.confirm("Are you sure?", function (result) { 
     if (result) { 
      __doPostBack(PostBackBtnMake(e.id), '') 
     } 
    }); 

    return _result; 
} 

그것은 나를 위해 일했습니다.

관련 문제