Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have used the following script to check whether an item is selected from grid view or not which works fine. When I am showing a confirm box and if the user selects OK I am returning to true if not False. But on Ok I am unable to delete the selected item from the grid view can any one help.

C#
<script type="text/javascript">
    $(document).ready(function () {
        $("#ContentPlaceHolder1_btnDelete").click(function () {
            var gv = document.getElementById("<%=grdPayroll.ClientID%>");
            var rbs = gv.getElementsByTagName("input");
            var flag = 0;
            for (var i = 0; i < rbs.length; i++) {
                if (rbs[i].type == "checkbox") {
                    if (rbs[i].checked) {
                        flag = 1;
                        break;
                    }
                }
            }
            if (flag == 0) {
                jAlert('Select One', 'Alert Dialog');
            }
            else {
                $("#ContentPlaceHolder1_btnDelete").click(function () {
                    var gv = document.getElementById("<%=grdPayroll.ClientID%>");
                    var rbs = gv.getElementsByTagName("input");
                    var flag = 0;
                    for (var i = 0; i < rbs.length; i++) {
                        if (rbs[i].type == "checkbox") {
                            if (rbs[i].checked) {
                                flag = 1;
                                break;
                            }
                        }
                    }
                    if (flag == 0) {
                        jAlert('Select One', 'Alert Dialog');
                        //return false;
                    }
                    else {
                        jConfirm('Can you confirm this?', 'Confirmation Dialog', function (r) {
                            if (r == true)
                                return true;
                            else
                                return false;
                        });
                        //return false;
                    }
                });
            }
            return false;
        });
    });
</script>
Posted

1 solution

Do you want to delete items from the gridview, or from the table that is on the client side ? You're checking if the boxes are checked twice, could it change ? You need to add code to remove the items, there's tons of tutorials on the web on how to do that. Here[^] is just one example.
 
Share this answer
 
Comments
demouser743 9-Feb-12 9:30am    
I need to delete from database and update the grid. I have written the code for that but from the script I am not getting return value as true.
Christian Graus 9-Feb-12 9:39am    
You can use Chrome to step through your js and debug it. Your code just returns true or false, I don't see any line that does an AJAX call to delete the data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900