GridView ItemTemplate 内的 ModalPopupExtender
如何使用包含 LinkButton 的 GridView TemplateField 来在单击时显示模式?我有几行数据,我想在单击该行中的“编辑”链接按钮时更新其详细信息。在模态显示之前,我需要通过代码隐藏加载大量数据。
我正在尝试以下操作,但无法在事件处理程序中执行 Modal1.Show()
因为它位于 TemplateField 中:
<ItemTemplate>
<asp:Button runat="server" ID="HiddenForModal" style="display: none" />
<ajaxToolkit:ModalPopupExtender ID="Modal1" runat="server" TargetControlID="HiddenForModal" PopupControlID="pnlModal" />
<asp:LinkButton ID="btnEdit" runat="server" Text="Edit" onclick="btnEdit_Click" />
<asp:LinkButton ID="btnDelete" runat="server" Text="Delete"></asp:LinkButton>
</ItemTemplate>
谢谢, 标记
How do I use a GridView TemplateField containing a LinkButton that is to display the modal on click? I have rows of data that I want to update the details of when clicking the 'Edit' LinkButton in that row. There is a bunch of data I need to load via codebehind just before the Modal displays.
I was trying the following, but I can't do Modal1.Show()
in the event handler because it's in a TemplateField:
<ItemTemplate>
<asp:Button runat="server" ID="HiddenForModal" style="display: none" />
<ajaxToolkit:ModalPopupExtender ID="Modal1" runat="server" TargetControlID="HiddenForModal" PopupControlID="pnlModal" />
<asp:LinkButton ID="btnEdit" runat="server" Text="Edit" onclick="btnEdit_Click" />
<asp:LinkButton ID="btnDelete" runat="server" Text="Delete"></asp:LinkButton>
</ItemTemplate>
Thanks,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关键是要知道 GridView 中的哪一行是被单击的 LinkButton。您可以通过多种方式执行此操作,但我实现它的方式是在 RowCommand 事件中捕获它。然后您可以通过 FindControl(..) 访问单击行中的 ModalPopupExtender。
页面:
代码隐藏:
此外,因为您在回发时打开模式,所以您实际上并不需要 ItemTemplate 中的 ModalPopupExtender (或隐藏按钮)。您可以将其移出并将其放在页面上(通过弹出 div),然后只需调用 Show() 方法即可。
页面:
代码隐藏:
谢谢,祝你好运!
The key is knowing which row in the GridView was the LinkButton that was clicked. You can do this several ways but the way I implemented it is to capture it in the RowCommand event. Then you can access the ModalPopupExtender in the clicked row via FindControl(..).
Page:
Codebehind:
Additionally, because you are opening the modal on a postback anyways you don't actually need the ModalPopupExtender (or the hidden button) in the ItemTemplate. You can move that out and put it on the page (by your popup div) and can simply call the Show() method.
Page:
Codebehind:
Thanks, good luck!