how to delete grid view row in java script with example

Posted by Venky.Net under JavaScript on 4/11/2014 | Points: 10 | Views : 804 | Status : [Member] | Replies : 2

i am using grid gridview contains four column,the forth column have delete button image and bind gridview. i want java script for delete javascript function with example.


Posted by: Rasagna on: 12/22/2015 [Member] Starter | Points: 25

Consider the below example.
we need to modify SqlDataSource of Gridview in the following way for delete to work and also delete column of gridview must be templated. like below inside columns tag itself in gridview code i.e. in .aspx file
<asp:TemplateField ShowHeader="False" AccessibleHeaderText="Delete" HeaderText="Delete">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return ConfirmOnDelete('');"></asp:LinkButton>

SqlSource modified in aspx file
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myconnectionstring %>" SelectCommand="SELECT * FROM [EmpInfo2] WHERE Employee_Id=@Employee_Id OR @Employee_Id IS NULL" CancelSelectOnNullParameter="false" DeleteCommand="DELETE [EmpInfo2] WHERE Employee_Id=@Employee_Id">
<asp:QueryStringParameter Name="Employee_Id" DbType = "String" Direction = "Input" QueryStringField="Employee_Id" DefaultValue="" ConvertEmptyStringToNull="True" />

then in aspx.cs file
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowState != DataControlRowState.Edit)
if (e.Row.RowType == DataControlRowType.DataRow)
String Employee_Id = e.Row.Cells[0].Text;
LinkButton lb = (LinkButton)e.Row.Cells[15].FindControl("LinkButton1");
if (lb != null)
lb.Attributes.Add("onclick", "return ConfirmOnDelete("+ Employee_Id +")");

I took .cells[15] as in my gridview delete column is 15th and employee_id(Primarykey) is the first and we so is given .cells[0].
In .aspx file in head tag of gridview write the following script
function ConfirmOnDelete(Employee_Id) {
if (confirm("Are you sure to delete: " + Employee_Id + "?") == true)
return true;
return false;

Venky.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vinothkumar on: 4/11/2014 [Member] Starter | Points: 25


See this...

Vinoth kumar

Venky.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response