add

Thursday, 12 September 2013

multiple deletes using checkbox in asp.net

 string strID = string.Empty;

        for (int i = 0; i < gvproviders.Rows.Count; i++)
        {
            CheckBox chkDelete = (CheckBox)gvproviders.Rows[i].
                             Cells[0].FindControl("chkname");
            if (chkDelete != null)
            {
                if (chkDelete.Checked)
                {

                    Label lbldeleteid = (Label)gvproviders.Rows[i].Cells[1].FindControl("controlid");
                    if (strID != string.Empty)
                        strID += ",";
                    strID += "" + lbldeleteid.Text + "";
                    //strID  = lbldeleteid.Text;
                    //idCollection.Add(strID);
                }
            }
        }
        string s1 = "delete from tblname where PId in(" + strID + ")";
       
        con.db1.Open();
        OleDbCommand cmd = new OleDbCommand(s1, con.db1);
       
        int j = Convert.ToInt32(cmd.ExecuteNonQuery());
        con.db1.Close();

No comments:

Post a Comment