Hey there,
Try
dt.AcceptChanges();
after
dt.Rows.RemoveAt(i);
and move
if (Session["CurrentTable"] != null)
{
dt = (DataTable)Session["CurrentTable"];
outside the loop
Also, in this statement,
dt.Rows.RemoveAt(i);
you cannot use i as the index to delete. Introduce another variable e.g. int j = 0 and increment it only when the item is not deleted. This is because whenever you remove a row from DataTable, it will not longer match the data/indexes of listview and you'll get an IndexOutOfBoundsException exception.
Do something like this:
protected void btndelete_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
if (Session["CurrentTable"] != null)
{
dt = (DataTable)Session["CurrentTable"];
int j = 0;
for (int i = 0; i < listview1.Items.Count; i++)
{
ListViewDataItem items = listview1.Items[i];
CheckBox chkBox = (CheckBox)items.FindControl("chkdel");
if (chkBox.Checked == true)
{
dt.Rows.RemoveAt(j);
dt.AcceptChanges();
}
else
{
j++;
}
}
Session["CurrentTable"] = dt;
listview1.DataSource = dt;
listview1.DataBind();
BindDataToGridviewDropdownlist();
}
}
best of luck