【发布时间】:2015-11-06 15:18:44
【问题描述】:
我有以下asp:Repeater:
<asp:Repeater runat="server" ID="rptResults">
<ItemTemplate>
<div class="FileFile Large pdf SearchResult">
<a href='<%# DirectCast(Container.DataItem, FileFolder).Link %>' style="text-decoration:none">
<%# DirectCast(Container.DataItem, FileFolder).BackgroundHTML%>
<p style="float:left;line-height:32px;margin:0px"><%# DirectCast(Container.DataItem, FileFolder).Filename%></p>
</a>
<p style="float:left;line-height:32px;margin:0px; margin-left:20px;">Path: <%# DirectCast(Container.DataItem, FileFolder).Link%></p>
<asp:Button runat="server" ID="btnDeleteFile" Name="<%# DirectCast(Container.DataItem, FileFolder).Link%>" Text="Delete" Style="float:right;margin-top:8px;cursor:pointer;"/>
</div>
</ItemTemplate>
</asp:Repeater>
我的问题是尝试设置 OnCLick 侦听器。
首先我尝试过:
<asp:Button runat="server" OnClick="btnDeleteFile_Click" ID="btnDeleteFile" Name="<%# DirectCast(Container.DataItem, FileFolder).Link%>" Text="Delete" Style="float:right;margin-top:8px;cursor:pointer;"/>
和:
Protected Sub btnDeleteFile_Click(sender As Object, e As System.EventArgs)
Response.Write("KDKDK")
Response.End()
End Sub
但这导致Invalid postback or callback argument.
我怀疑这是因为我无法在中继器内设置OnCLick 侦听器?
然后我尝试了:
<asp:Button runat="server" ID="btnDeleteFile" Name="<%# DirectCast(Container.DataItem, FileFolder).Link%>" UseSubmitBehavior="false" Text="Delete" Style="float:right;margin-top:8px;cursor:pointer;"/>
和
Protected Sub rpt_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs)
If e.CommandName = "Save" Then
'Save
End If
End Sub
没有导致回发错误,但没有触发事件。我怀疑这是因为没有将监听器分配给按钮?
如果我添加一个句柄,例如:
Protected Sub rpt_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rpt.ItemCommand
哪个给出了错误:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
但我看不到如何分配 WithEvents 变量,而且我不确定这在转发器中是否有效。
我不会让您每次尝试都感到厌烦,但我已经搜索了所有我能找到的东西,但找不到任何告诉我如何设置此 OnCLick 事件的东西?
【问题讨论】:
-
尝试将 OnItemCommand 添加到中继器并将按钮设置为 CommandButton。 msdn.microsoft.com/en-us/library/…