在中继器中删除 [英] Delete In Repeater

查看:64
本文介绍了在中继器中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于视频上传和播放的Web应用程序.管理员可以上传,用户可以查看上传的文件.我会自动填充从数据库到转发器的链接.我的目标是管理员可以删除上传的文件.还要从数据库中删除.我正在使用SQl experess和VS2005.如何执行此操作?

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?

推荐答案

放置一个按钮或您喜欢的任何其他控件,并为该按钮设置命令名称属性等于删除",例如,在命令参数中放置任何id属性来知道要删除的行,然后在转发器ItemCommand事件中检查此命令名称,然后执行删除功能.

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.

示例:

<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
    }
}

删除代码将如下所示:

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

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

这篇关于在中继器中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆