Deleting multiple checked items from a ListView

Hi Guys,

During developement we do encounter some scenarios where user has checked some of the items from the
ListBox and want to delete those selected items on a single button click.
Below is the code sample that i wrote to do the same stuff.

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(); }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s