Skip to content

Code to delete records using Selectall checkbox in C#

Sandhya Bhosale

Asked Oct 17, 2006, 11:49 PM EDT2 answers
Share
LinkedInX
I have created a template column for Select All  in datagrid to delete records for a particular page  when Select All checkbox is checked.

But the entire records of the table are deleted when the Select All checkbox is checked and Delete button is clicked.

What could be the solution... I require code to delete  the records on button click.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    var xmlDoc,iCount,nodes,OptNodes,blnReturn;
     clearvalue();
     xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
     xmlDoc.async="false";
     
     blnReturn = xmlDoc.load("/Corporate_Departments/Human_Resources/HR_Support_Center/eGO_Forms/includes/ldap_Query.asp?Filter=" + strFilter);
     if (blnReturn)
      {
       nodes=xmlDoc.documentElement.childNodes;
       
       for (iCount=0; iCount < nodes.length;iCount++)
       {
        document.frmSubmit.item("txtName").value = nodes.item(iCount).childNodes.item(0).text;
        document.frmSubmit.item("txtMgrName").value = nodes.item(iCount).childNodes.item(5).text;
        document.frmSubmit.item("txtMgrPH").value = nodes.item(iCount).childNodes.item(9).text;
        document.frmSubmit.item("txtManagerEmpID").value = nodes.item(iCount).childNodes.item(16).text;
       }
      }
     else
      {
       alert("User Information not available in eGO, this might be due to invalid employee id or the User left Best Buy. Please check the number and try again.");
      
       document.frmSubmit.item("txtEmpID").focus();
       document.frmSubmit.item("txtEmpID").value = "";
       document.frmSubmit.item("txtName").value = "";
       document.frmSubmit.item("txtMgrName").value = "";
       document.frmSubmit.item("txtMgrPH").value = "";
       document.frmSubmit.item("txtManagerEmpID").value = "";
      }
     }
    0
  • 0
    Thank you for the information.


    Actually I have written the code for delete button click as follows:

    protected void btndelete_Click(object sender, EventArgs e)

    {


    CheckBox SelectAll;

    foreach (DataGridItem dgi in MyDataGrid.Items)

    {

    int topicid;

    string strSQL;

    SelectAll = dgi.FindControl("chkSelect");  // chkSelect is the Item template of checkbox.

    if (SelectAll.Checked)

    {

    topicid = Convert.ToInt32(MyDataGrid.DataKeys(dgi.ItemIndex)).ToString();

    strSQL = "delete from Admin_Add_Newsletter_Topic where Topic_Id=" & topicid & ";";

     

    SqlConnection con = new SqlConnection(ConnectionString);

    SqlCommand cmd = new SqlCommand(strSQL, con);

    cmd.CommandType = CommandType.Text;

    con.Open();

    cmd.ExecuteNonQuery();

    con.Close();

    }

    }

    }

    However, it does not work. 
    Also, I have not converted topic id to template column. Can that be a problem???  

    0