2017-09-22 23 views
0

我有一個asp:GridView包含一個CommandField。試圖創建確認對話框使用CommandField從GridView刪除一行,將刪除,無論選擇

當我點擊刪除圖像時,OnRowDeleting將在後面的代碼中調用。

我想添加一個確認對話框,使用jquery。

嘗試這樣的:

$('input[alt="Ta bort"]').click(function(e) 
{ 
    var target = e.which; 

    var tr = $(target).closest('tr'); 
    var td = tr.find("td:first"); 

    if (!confirm("Do you want to remove the line where the first cell reads" + td.text() + "?")) 
    { 
     return false; 
    } 
}); 

我不知道文本「鉭BORT」實際上是如何進入該alt屬性,在我的語言的「刪除」,必須自動生成的,因爲沒有在我的aspx代碼爲「Ta bort」。除了使用該替代文本之外,我找不到任何其他方式輕鬆編寫選擇器。

確認出現,但事件永遠不會被取消。這意味着即使我選擇「否」,該行也會被刪除。

爲什麼?

我也試過e.preventDefault();

我不想創建一個模板列,而不是CommandField中作爲Delete Confirmation Message in CommandField?

回答

0

建議你可以使用如下

<asp:LinkButton ID="lnkDelete" runat="server" CausesValidation="False" 
         CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this record');"></asp:LinkButton> 

請參閱本reference link

+0

我如果可能的話,想繼續使用CommandField。 –