Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void btndelete_Click(object sender, EventArgs e)
{
    DataTable dt = new DataTable();

    for (int i = 0; i < listview1.Items.Count; i++)
    {
        ListViewDataItem items = listview1.Items[i];
        CheckBox chkBox = (CheckBox)items.FindControl("chkdel");

        if (chkBox.Checked == true)
        {
            if (Session["CurrentTable"] != null)
            {
                dt = (DataTable)Session["CurrentTable"];
                dt.Rows.RemoveAt(i);
            }
        }
        else
        {
        }
    }

    Session["CurrentTable"] = dt;
    listview1.DataSource = dt;
    listview1.DataBind();
    BindDataToGridviewDropdownlist();     
}

Here it is deleting one row only. How to delete multiple checked items in listview?
Posted
Updated 24-Sep-13 1:35am
v3

1 solution

C#
protected void btndelete_Click(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
 
    for (int i = 0; i < listview1.Items.Count; i++)
    {
        ListViewDataItem items = listview1.Items[i];
        CheckBox chkBox = (CheckBox)items.FindControl("chkdel");
 
        if (chkBox.Checked == true)
        {
            if (Session["CurrentTable"] != null)
            {
                dt = (DataTable)Session["CurrentTable"];
                dt.Rows.RemoveAt(i);

            }
        }
        else
        {
        }
           dt.AcceptChanges();//You are missing this line
    }
 
    Session["CurrentTable"] = dt;
    listview1.DataSource = dt;
    listview1.DataBind();
    BindDataToGridviewDropdownlist();     
}


i hope this will work for you regards......:)
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900