Please refer this code
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
Width="330" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
<br />
<asp:Button ID="btnDelete" Text="Delete" runat="server" />
jQuery
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnDelete]").click(function () {
$("[id*=GridView1] tr [id*=chkSelect]:checked").each(function () {
$(this).closest('tr').remove();
});
return false;
});
});
</script>
Namespace
using System.Data;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
Demo
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
table
{
border: 1px solid #ccc;
}
table th
{
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td
{
padding: 5px;
border-color: #ccc;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnDelete]").click(function () {
$("[id*=GridView1] tr [id*=chkSelect]:checked").each(function () {
$(this).closest('tr').remove();
});
return false;
});
});
</script>
</head>
<body>
<table cellspacing="0" rules="all" border="1" id="GridView1" style="width: 330px;
border-collapse: collapse;">
<tr style="color: White; background-color: #3AC0F2;">
<th scope="col">
</th>
<th scope="col">
Id
</th>
<th scope="col">
Name
</th>
<th scope="col">
Country
</th>
</tr>
<tr>
<td>
<input id="GridView1_chkSelect_0" type="checkbox" name="GridView1$ctl02$chkSelect" />
</td>
<td style="width: 30px;">
1
</td>
<td style="width: 150px;">
John Hammond
</td>
<td style="width: 150px;">
United States
</td>
</tr>
<tr>
<td>
<input id="GridView1_chkSelect_1" type="checkbox" name="GridView1$ctl03$chkSelect" />
</td>
<td style="width: 30px;">
2
</td>
<td style="width: 150px;">
Mudassar Khan
</td>
<td style="width: 150px;">
India
</td>
</tr>
<tr>
<td>
<input id="GridView1_chkSelect_2" type="checkbox" name="GridView1$ctl04$chkSelect" />
</td>
<td style="width: 30px;">
3
</td>
<td style="width: 150px;">
Suzanne Mathews
</td>
<td style="width: 150px;">
France
</td>
</tr>
<tr>
<td>
<input id="GridView1_chkSelect_3" type="checkbox" name="GridView1$ctl05$chkSelect" />
</td>
<td style="width: 30px;">
4
</td>
<td style="width: 150px;">
Robert Schidner
</td>
<td style="width: 150px;">
Russia
</td>
</tr>
</table>
<br />
<input type="submit" name="btnDelete" value="Delete" id="btnDelete" />
</body>
</html>
Demo