This will not delete the Data from Database it will just delete the Data from DataTable that you have kept in ViewState.
HTML
<asp:ListView ID="lvCustomers" runat="server" OnItemDeleting="lvCustomersItemDeleting"
GroupPlaceholderID="groupPlaceHolder1" ItemPlaceholderID="itemPlaceHolder1">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<th>
CustomerId
</th>
<th>
ContactName
</th>
<th>
Country
</th>
<th>
</th>
</tr>
<asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<asp:Label ID="lblCustomerId" Text='<%# Eval("CustomerId") %>' runat="server" />
</td>
<td>
<asp:Label ID="lblContactName" Text='<%# Eval("ContactName") %>' runat="server" />
</td>
<td>
<asp:Label ID="lblCountry" Text='<%# Eval("Country") %>' runat="server" />
</td>
<td>
<asp:LinkButton ID="lnkDelete" CommandName="Delete" runat="server" Text="Delete"></asp:LinkButton>
</td>
</ItemTemplate>
</asp:ListView>
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("CustomerId", typeof(int)),
new DataColumn("ContactName", 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");
ViewState["DataTable"] = dt;
lvCustomers.DataSource = dt;
lvCustomers.DataBind();
}
}
protected void lvCustomersItemDeleting(object sender, ListViewDeleteEventArgs e)
{
DataTable dt = (DataTable)ViewState["DataTable"];
dt.Rows.RemoveAt(e.ItemIndex);
ViewState["DataTable"] = dt;
lvCustomers.DataSource = dt;
lvCustomers.DataBind();
}