Reputation: 533
I have a web application for video upload and play.The administrator can upload and users can view the uploaded files.I am automatically populating links from database to a repeater.My target is the administrator can delete the uploaded file.The file also delete from the database.I am using SQl experess and VS2005 .How can i do this?
Upvotes: 0
Views: 10912
Reputation:
if u'd like to use custom confirmation ( like jquery dialog,bootboxjs etc.. ) then you have to generate button's "postback string" or get it somehow. asp.net gives such as postback name after rendering the page; __doPostBack('ctl00$ContentPlaceHolder1$btnDeleteSelected',''). after realizing this i wrote a js function which is generates button's postback str;
function PostBackBtnMake(id) { // id : ContentPlaceHolder1_btnDeleteSelected
var result;
var temp = id.split('_');
result = 'ctl00$' + temp[0] + '$' + temp[1];
return result;
}
then i be able to use in custom confirmation box (in this case i used bootboxjs);
function PostBackBtn(e) {
var _result = false;
bootbox.confirm("Are you sure?", function (result) {
if (result) {
__doPostBack(PostBackBtnMake(e.id), '')
}
});
return _result;
}
it's worked for me, i hope it helps you too.
Upvotes: 0
Reputation: 68932
Put a button or any other control you like, and set for this button the command name property equal "delete" for example, put any id in the command argument property to know which row you will delete, and in the repeater ItemCommand event check for this command name then do the delete function.
Example:
<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
}
}
Delete Code will be something like this:
Dim connectionString As String = ConfigurationManager.ConnectionStrings("UploadConnectionString").ConnectionString
Dim adapter As New SqlDataAdapter("DELETE FROM FileM where id=" & e.CommandArgument.ToString(), connectionString)
Upvotes: 8