Remove GridviewRow using Javascript?

I have a gridview that has a row add and remove object. I want to stop how I can delete a specific row of the gridview when the corresponding delete button is clicked.

I searched everywhere but didn't find anything very useful for me

Here is my code

<asp:TemplateField>
  <ItemTemplate>
     <asp:LinkButton ID="gdlbtnRemove" runat="server" 
     OnClientClick="RemoveRow(this)">Remove</asp:LinkButton>
  </ItemTemplate>
</asp:TemplateField>

      

This is my javascript code

<script type="text/javascript">
  function RemoveRow(rowindex,objref)
  { 
    var row=objref.parentNode.parentNode;
    row.Remove();  
  }
 </script>

      

I'm new to javascript ........

+3


source to share


2 answers


Try the following:

apsx:

<ItemTemplate> 
    <asp:LinkButton  ID="gdlbtnRemove" runat="server"     
     OnClientClick="return RemoveRow(this)">Remove</asp:LinkButton> 
</ItemTemplate>

      



JavaScript:

function RemoveRow(item) {
    var table = document.getElementById('myGridView');
    table.deleteRow(item.parentNode.parentNode.rowIndex);
    return false;
}

      

+3


source


Old post I know, but Tsachi's answer was almost perfect for me except

it

var table = document.getElementById('GridviewID');

      



should have been this

var table = document.getElementById("<%= GridviewID.ClientID %>");

      

If anyone else is looking at this

+1


source







All Articles