如何确定在gridview中单击了哪个按钮
本文关键字:按钮 单击 何确定 gridview | 更新日期: 2023-09-27 17:49:43
我有一个gridview和我的gridview有一个模板字段的图像按钮,用于删除一行。目前,我使用行命令和行warguement这个图像按钮来识别想要删除的行。但我需要实现以下场景:
我想当用户点击imagebutton,没有回发发生,一个模态框(bootstrap模态)打开,只有当用户点击是,我确定按钮在模态,回发发生和数据删除…
这是可能的asp.net gridview,如果是,我怎么能确定什么按钮点击在"是的,我确定按钮"?
谢谢
这是可能的。请尝试下面的代码:
<script type="text/javascript">
function ShowModal(gridItemIndex)
{
$(document).ready(function ()
{
$('#mymodal').modal('show');
var row = gridItemIndex.parentNode.parentNode;
var rowIndex = row.rowIndex-1; //row index of that row.
document.getElementById("<%=hfID.ClientID %>").value =rowIndex;
});
}
</script>
<asp:gridview id="yourGridView" onrowcommand="GridView_RowCommand"
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton name="btnDelete" CommandName="Delete" OnClientClick="return ShowModal(this);" ImageUrl="/imagepath.pgn" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</asp:gridview>
然后在后面的代码中使用GridView
的以下事件。
protected void GridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName=="Delete")
{
// Write your delete code here...
}
}