Thursday, January 26, 2012

Getting checkbox selected Gridview Rows in ASP.Net

Following is the line of code use to get the checked box selected rows of grid and getting the columns values from the gridview source DataTable.
DataTable dtGetStTable = (DataTable)ViewState["dtNewStudents"];

//Looping throgh Grid and deleting row after finding the checked row
for (int i = dtGetStTable.Rows.Count - 1; i > -1; i--)
{
    GridViewRow row = GridView1.Rows[i];
    bool isChecked = ((CheckBox)row.FindControl("CheckBox1")).Checked;

    if (isChecked)
    {
        try
        {
            string RollNo = dtGetStTable.Rows[i]["RollNo"].ToString();
            string Class = dtGetStTable.Rows[i]["Class"].ToString();
            string Division = dtGetStTable.Rows[i]["Division"].ToString();
            //Deleting the Reocrd from DataBase
            TotalRecordDeleted += objSRE.DeleteTheSelectedRecord(RollNo, Class, Division);

            dtGetStTable.Rows[i].Delete();
            dtGetStTable.AcceptChanges();
        }
        catch (Exception ex)
        {

            //throw;
        }
    }
}

2 comments:

  1. Join the top Python Training in Hyderabad at AI Patasala and take your career to an entirely new level in the field.
    AI Patasala Python Course

    ReplyDelete
  2. With so many books and articles coming up to give gateway to make-money-online field and confusing reader even more on the actual way of earning money, data science course in kanpur

    ReplyDelete