2014-12-26 35 views
1

我有一個grdiview,其中添加了多重刪除功能。請查看代碼,供大家參考: -按鈕單擊上的多重刪除複選框不按要求工作

<script type="text/javascript"> 
    function ValidateAll() { 
     var chkselectcount = 0; 
     var gridview = document.getElementById('<%= grdTeacherProfile.ClientID %>'); 
     for (var i = 0; i < gridview.getElementsByTagName("input").length; i++) { 
      var node = gridview.getElementsByTagName("input")[i]; 

      if (node != null && node.type == "checkbox" && node.checked) { 
       chkselectcount = chkselectcount + 1; 
      } 
     } 
     if (chkselectcount == 0) { 
      alert("Please select atleast One CheckBox"); 
      return false; 
     } 
     else { 
      ConfirmationBox(); 
     } 
    } 
    function ConfirmationBox() { 
     var result = confirm("Are you sure, you want to delete the Users ?"); 
     if (result) { 
      return true; 
     } 
     else { 
      return false; 
     } 
    } 
</script> 

也看到按鈕HTML: -

<asp:Button ID="btnDelete" runat="server" CausesValidation="false" CssClass="btn btn-danger" Text="Delete" OnClick="btnDelete_Click" OnClientClick="javascript:return ValidateAll();" /> 

的問題是, 當我檢查的複選框,然後點擊刪除按鈕,它要求確認。當我點擊取消時,它仍會從Gridview以及sql table中刪除該行。

我應該怎麼做才能正確工作。 ?請建議

+0

'OnClick =「btnDelete_Click」'嘗試刪除它。 – Jai

+0

@Jai:很好,Shekar給出的答案正在工作.. – BNN

回答

1

我認爲你需要使用

return ConfirmationBox(); 

,而不是

ConfirmationBox(); 

所以,你的代碼變得

function ValidateAll() { 
    var chkselectcount = 0; 
    var gridview = document.getElementById('<%= grdTeacherProfile.ClientID %>'); 
    for (var i = 0; i < gridview.getElementsByTagName("input").length; i++) { 
     var node = gridview.getElementsByTagName("input")[i]; 

     if (node != null && node.type == "checkbox" && node.checked) { 
      chkselectcount = chkselectcount + 1; 
     } 
    } 
    if (chkselectcount == 0) { 
     alert("Please select atleast One CheckBox"); 
     return false; 
    } 
    else { 
     return ConfirmationBox(); 
    } 
} 

你需要從OnClientClick您可以使用刪除javascript:OnClientClick="return ValidateAll();"

+0

哪裏,在按鈕上? – BNN

+0

@NadeemKhan看我的編輯 –

+0

好的,休息都會一樣嗎? – BNN