For example we have 10 rows on our web page with check box in a grid view and we need only five rows to perform some action (i.e we want to delete those 5 records). with the help of below example code we can select our required rows to perform some action.
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; } } }
No comments:
Post a Comment