是的,這是可能的。請嘗試下面的代碼:
<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...
}
}
謝謝,但我想使用bootstrap模態,有什麼辦法嗎? –
是的,有一種方法。您可以創建一個帶有引導代碼的JavaScript函數。然後調用這個JavaScript函數,如:OnClientClick ='return yourJavascriptFunction();' –
好吧,但如何通過模態確認按鈕事件gridview rowindex? –