Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
I have a situation with gridview -

**Scenario** once someone click on delete,it gets the NOtif_recip_Id of that row and iterates through Gridview to see if NOTIF_RECIP_SEQ_NBR of any row corresponding to that NOTIF_RECIP_ID is greater or not.

I have written the code but I dont think this is a good way.Can someone tell any better way to do this.
JavaScript
<script type = "text/javascript">
        function GetSelectedRow(lnk) {
        debugger;
          var table, tbody, i, rowLen, row, j, colLen, cell;

            var result = confirm('Do you want to delete this value ?');
            if (result) {

                var x = document.getElementById('Label100');


                table = document.getElementById("GridView1");
                tbody = table.tBodies[0];

                var bool = true;
                var row = lnk.parentNode.parentNode;
                var rowIndex = row.rowIndex - 1;

                var RecipID = row.cells[0].innerText;
                var Sqqno = parseInt(row.cells[1].innerText);

                for (i = 1, rowLen = tbody.rows.length; i < rowLen; i++) {
                    row = tbody.rows[i];

                    var newrecipId = row.cells[0].innerText;
                    if (newrecipId == RecipID) {
                        cell = row.cells[1];

                        var newseq = parseInt(row.cells[1].innerText);
                        if (Sqqno < newseq) {
                            // debugger;
                            bool = false;
                            x = document.getElementById('Label100');
                            x.innerHTML = "ERROR-Delete RecipId with max Seqnumber";
                            x.style.display = "block";

                            return bool;
                            break;
                        }

                    }
                    else {
                        bool = true;
                    }

                }

                return bool;
            }
            else {
                return false;
            }

        }
    </script>


And the code for linkbutton is as follows:

ASP.NET
<asp:LinkButton ID="lnkSelect" runat="server" Text="Delete" CommandName = "Select"
         OnClientClick = "return GetSelectedRow(this)"  CommandArgument = '<%# Eval("NOTIF_RECIP_GUID")%>'  OnClick = "DeleteRecipdata" />
Posted
Updated 7-Jul-15 5:59am
v4
Comments
Suvendu Shekhar Giri 3-Jul-15 13:02pm    
Where is the code to delete ?
vicvis 6-Jul-15 2:35am    
Sir.I want to do ths iteration from Client Side.I have delete code in aspx.cs (which I havenot provided as not relevant and code will become cumbersome her.If you wantI can add that too
manognya kota 8-Jul-15 9:30am    
Try doing it in jquery with $.each().

1 solution

Hi,

You can try like,

C#
function GetSelectedRows() {
    $("#GridView1 tr").each(function () {
       
        var textBox = $(this).find("input[type='text']");
       //your code in here to check 
        }
    });
}



Hope this helps.
 
Share this answer
 

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