Click here to Skip to main content
14,331,142 members
Rate this:
Please Sign up or sign in to vote.
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.
<script type = "text/javascript">
        function GetSelectedRow(lnk) {
          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";
                   = "block";

                            return bool;

                    else {
                        bool = true;


                return bool;
            else {
                return false;


And the code for linkbutton is as follows:

<asp:LinkButton ID="lnkSelect" runat="server" Text="Delete" CommandName = "Select"

         OnClientClick = "return GetSelectedRow(this)"  CommandArgument = '<%# Eval("NOTIF_RECIP_GUID")%>'  OnClick = "DeleteRecipdata" />
Updated 7-Jul-15 5:59am
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

Rate this:
Please Sign up or sign in to vote.

Solution 1


You can try like,

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

Hope this helps.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100