【发布时间】:2018-06-01 16:58:42
【问题描述】:
我花了一整天的时间试图实现这一目标,但失败了。
我的页面上有一个 ASP.Net 中继器,并添加了一个 LinkButton,它会弹出一个漂亮的 Bootstrap 3 确认模式窗口(用于删除记录)。
我试图拼凑解决方案,但我的 Java 知识令我失望。
这是我的中继器:
<asp:Repeater OnItemCommand="rptImages_ItemCommand" ID="rptImages" OnItemCreated="rptImages_ItemCreated" OnItemDataBound="rptImages_ItemDataBound" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:Image ID="imgThumb" CssClass="product-image" runat="server" ImageUrl='<%# string.Format("~/{0}", Eval("ImageUrl")) %>' />
<asp:LinkButton ID="lbDelete" runat="server" CommandArgument='<%#Eval("ProductImageId")%>' CommandName="delete" data-toggle="tooltip" data-placement="top" title="Delete this record" OnClientClick="return ConfirmDelete()"><i class="image-button fa fa-trash"></i></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
这是我在页面顶部的 Java 脚本:
<script>
function ConfirmDelete() {
$('#DeleteModal').modal(); // initialized with defaults
// $('#DeleteModal').modal({ keyboard: false }) // initialized with no keyboard
// $('#DeleteModal').modal('show')
return false;
}
</script>
这是我的 Bootstrap 弹出窗口的代码:
<div class="modal fade" id="DeleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="H3">Delete this record?</h4>
</div>
<asp:UpdatePanel ID="upDel" runat="server">
<ContentTemplate>
<div class="modal-body">
Are you sure you want to delete this image?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<asp:Button ID="btnDeleteImage" runat="server" OnClick="btnDeleteImage_Click" CssClass="btn btn-danger" Text="Delete" />
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnDeleteImage" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
</div>
当我单击删除按钮时,会出现引导模式。在“取消”按钮上,模式关闭。在“删除”按钮上,模式也会关闭,但我的 gridview item 命令永远不会触发。
如果有任何帮助,我将永远感激不尽。
非常感谢您!
【问题讨论】:
-
btnDeleteImage_Click事件应该触发,在后面的代码中处理删除。也可以考虑btnDeleteImage_Command -
您好 fnostro,抱歉,您能详细说明一下吗?谢谢!
-
模态不是中继器的一部分,而是由中继器中的按钮触发的。当转发器被渲染时,它对模态一无所知。单击模态删除按钮应该触发按钮 Click 或 Command 事件,而不是中继器 ItemCommand 事件
-
您好 fnostro,非常感谢您的回复。不幸的是,我仍然有点困惑。我将如何获得模式中的按钮来触发中继器的行命令事件?甚至可能吗?谢谢!
-
我将把我的想法变成一个答案,我们超出了这个评论部分的范围:)
标签: .net twitter-bootstrap asprepeater