如何删除使用asp:XmlDataSource的asp:ListView?
我创建了一个 asp:ListView
并将其附加到 asp:XmlDataSource
。我想支持列表的删除命令,因此我添加了以下按钮:
<asp:Button runat="server" CommandName="Delete"
Text="Del" CausesValidation="false" />
它会抛出“不支持指定的方法”。关于如何实现此删除有什么想法吗?
I've created an asp:ListView
and attached it to an asp:XmlDataSource
. I would like to support the delete command for my list, so I've added the following button:
<asp:Button runat="server" CommandName="Delete"
Text="Del" CausesValidation="false" />
It throws an 'Specified method is not supported'. Any ideas on how to implement this delete?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XmlDataSource
不直接支持Delete
命令,您必须手动操作 XML 文档。至少有两种方法可以在您的页面中处理此问题。CommandName
更改为默认情况下不存在的命令,并在 ListView 的ItemCommand
事件处理程序中进行 XML 编辑。ItemCommand
事件处理程序的事件参数的类型为ListViewCommandEventArgs
,它具有一个CommandName
属性,该属性设置为您在按钮上设置的值。CommandName="Delete"
,并且在ItemDeleting
事件中,您必须取消该事件(以防止它尝试调用Delete
> 在您的XmlDataSource
控件上,您已经看到它不起作用)。然后在此处进行 XML 编辑。至于实际实现删除功能,您必须在代码隐藏中手动编辑 XML。 来自 MSDN 上的 XmlDataSource 类文档 :
An
XmlDataSource
doesn't support theDelete
command directly, you have to manipulate your XML document manually. There's at least 2 ways you can handle this in your page.CommandName
on your button to a command that doesn't exist by default, and do your XML editing in the ListView'sItemCommand
event handler. The event argument for theItemCommand
event handler is of typeListViewCommandEventArgs
which has aCommandName
property which gets set to the value you set on your button.CommandName="Delete"
, and in theItemDeleting
event you have to cancel the event (to keep it from trying to callDelete
on yourXmlDataSource
control, which you've already seen doesn't work). Then do your XML editing here.As far as actually implementing the delete functionality, you'll have to manually edit the XML in your codebehind. From the XmlDataSource Class documentation on MSDN: