2014-03-12 64 views
0

我有一個gridview和我的gridview有一個圖像按鈕的模板feild刪除一行。 目前我使用此圖像按鈕的rowcommand和rowargument來識別要刪除的行。但我需要實現以下場景:如何確定哪個按鈕被點擊gridview

我想當用戶點擊imagebutton,沒有回發發生,模態框(bootstrap模態)打開,並且只有當用戶點擊yesI確定按鈕在模態,回發和數據刪除...

這是可能的與asp.net gridview,如果是的話,我如何可以確定按鈕點擊「yesI'm確定按鈕」?

謝謝

回答

0

是的,這是可能的。請嘗試下面的代碼:

<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... 
    } 
} 
+0

謝謝,但我想使用bootstrap模態,有什麼辦法嗎? –

+0

是的,有一種方法。您可以創建一個帶有引導代碼的JavaScript函數。然後調用這個JavaScript函數,如:OnClientClick ='return yourJavascriptFunction();' –

+0

好吧,但如何通過模態確認按鈕事件gridview rowindex? –