Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
265
Issue deleting a row in webgrid
posted
I have a WebGrid where I am adding rows.
Now there is a delete button on the page which deletes the selected row from the grid.

My problem is when say my grid has 2 rows and they sort the grid and then select the second row and press delete. It deletes the first row and when I now select my first row and now press delete it keeps on popping up my confirm window a couple of times and then delete the row. Where am i going wrong. here is my code.

function DeleteDataFromGrid()
    {
         var gridClientId = '<%=grid.ClientID %>';
         var grid = igtbl_getGridById(gridClientId);
         igtbl_getGridById(gridClientId).AllowDelete=1;
         var activeRow = igtbl_getActiveRow(gridClientId);
         var rowId, row;
         
        if(grid.Rows.length >0)
        {
            if(igtbl_getLength(grid.SelectedRows)>0)
            {
                for(rowId in grid.SelectedRows)
                {                                
                       if (confirm('Are you sure you would like to delete this item?'))
                       {              
                                igtbl_deleteRow(gridClientId,rowId);                        
                       }                                                      
                }        
            }
            else
            {
              alert("Please select an item to delete.");
            }
        }
        else
        {
            alert("No item to delete.");
        }
}
Parents
No Data
Reply Children