Social Icons

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;
        }
    }
}

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete

 

Sample text

Sample Text