Here I have created sample that full fill your requirement.
HTML
<div>
<asp:DataList ID="DataList1" runat="server">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
Customer Id
</td>
<td>
Name
</td>
<td>
Country
</td>
<td>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblCustomerId" Text='<%# Eval("CustomerId") %>' runat="server" />
</td>
<td>
<asp:Label ID="lblName" Text='<%# Eval("Name") %>' runat="server" />
</td>
<td>
<asp:Label ID="lblCountry" Text='<%# Eval("Country") %>' runat="server" />
</td>
<td>
<asp:LinkButton ID="lnkDelete" Text="Delete" runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=DataList1] [id*=lnkDelete]").click(function () {
if (confirm("Do you want to delete this Customer?")) {
var row = $(this).closest("tr");
var customerId = parseInt(row.find("[id*=lblCustomerId]").html());
$.ajax({
type: "POST",
url: "CS.aspx/DeleteCustomer",
data: '{customerId: ' + customerId + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
if (r.d) {
row.remove();
if ($("[id*=DataList1] td").length == 0) {
$("[id*=DataList1] tbody").append("<tr><td colspan = '4' align = 'center'>No records found.</td></tr>")
}
alert("Customer record has been deleted.");
}
}
});
}
return false;
});
});
</script>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindDataList();
}
}
private void BindDataList()
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
DataList1.DataSource = dt;
DataList1.DataBind();
}
}
}
}
[WebMethod]
public static bool DeleteCustomer(int customerId)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("DELETE FROM Customers WHERE CustomerId = @CustomerId"))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@CustomerId", customerId);
con.Open();
int rowsAffected = cmd.ExecuteNonQuery();
con.Close();
return rowsAffected > 0;
}
}
}
Screenshot
