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 to share