protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                BLDocBoyHistory bldb = new BLDocBoyHistory();
                setparameters();
                if (Session["DBHID"] != null)
                {
                    int intDBHID = int.Parse(Session["DBHID"].ToString());
                    int intDBID = getDocBoyID();
                    bldb.updateDocBoyHistory1(intProjectID, dtDate, intDBID, strDocumentBoy, strRemarks, intDBHID);
                    lblErrorMsg.Text = "";
                    Session["DBHID"] = null;
                    lblresult.Visible = true;
                    lblresult.Text = "Document Boy history Successfully updated";
                }
                else
                {
                    int intDBID = getDocBoyID();
                    // intDBID = int.Parse(lblId.Text);
                    bldb.saveDocumentBoyHistory1(dtDate, intDBID, strDocumentBoy, strRemarks, intProjectID);
                    lblErrorMsg.Text = "";
                    Session["DBHID"] = null;
                    lblresult.Visible = true;
                    lblresult.Text = "Document Boy history Successfully added";
                }

                lblId.Text = "";
                lblCode.Text = "";
                txtRemarks.Text = "";
                string strName1 = ddlSelDocBoy.SelectedItem.Text;
                int intProjectId = int.Parse(lblPrjId.Text);
                SqlDataReader dr1 = bldb.getDocBoyhistoryId1(strName1, intProjectId);
                if (dr1.HasRows)
                {
                    while (dr1.Read())
                    {
                        intDBHID = dr1.GetInt32(0);
                    }
                    dr1.Close();
                }
                //Data Table to get Selected Documents and insert record into document boy history details
                BLDocBoyHistory bldbh = new BLDocBoyHistory();
                BLProject blp = new BLProject();
                DataTable dtSelDocument = new DataTable();
                DataTable dtUnSelDocument = new DataTable();
                dtSelDocument.Columns.AddRange(new DataColumn[1] { new DataColumn("Docid") });
                dtSelDocument.Columns.AddRange(new DataColumn[1] { new DataColumn("Document") });
                dtUnSelDocument.Columns.AddRange(new DataColumn[1] { new DataColumn("Docid") });
                dtUnSelDocument.Columns.AddRange(new DataColumn[1] { new DataColumn("Document") });
                foreach (GridViewRow gvrow in GVSelPendingDoc.Rows)
                {
                    if (gvrow.RowType == DataControlRowType.DataRow)
                    {
                        //finding the checkbox in the gridview
                        CheckBox ChkBxSelDoc = (gvrow.Cells[0].FindControl("ChkBxSelDoc") as CheckBox);
                        // checking which checkbox are selected
                        if (ChkBxSelDoc.Checked)
                        {
                            int docid = int.Parse(gvrow.Cells[1].Text);
                            string Doc = gvrow.Cells[2].Text;
                            dtSelDocument.Rows.Add(docid, Doc);
                        }
                        else
                        {
                            string Docid = gvrow.Cells[1].Text;
                            string Doc = gvrow.Cells[2].Text;
                            dtUnSelDocument.Rows.Add(Docid, Doc);
                        }
                    }
                }

                //DataTable dt = (DataTable)dtSelDocument;
                for (int i = 0; i < dtSelDocument.Rows.Count; i++)
                {
                    int docid = int.Parse(dtSelDocument.Rows[i].Field<string>(0));
                    string doc = dtSelDocument.Rows[i].Field<string>(1);
                    bldb.saveDocBoyHistoryDetails1(intDBHID, docid, doc);

                    Session["DBHID"] = null;
                    lblresult1.Visible = true;
                    lblresult1.Text = "Document Boy history details Successfully added";
                }
                for (int i = 0; i < dtUnSelDocument.Rows.Count; i++)
                {
                    int docid = int.Parse(dtUnSelDocument.Rows[i].Field<string>(0));
                    bldbh.delUnselectedDocOfDocBoy1(intDBHID, docid);
                }
                if (dtUnSelDocument != null)
                {
                    GVSelPendingDoc.DataSource = dtUnSelDocument;
                    GVSelPendingDoc.DataBind();
                }

                //show grid for document boy history details
                fillgridDocBoyHistoryDetails();
                //lblresult.Text = "Exist";
            }
            catch (Exception ex)
            {
                lblCatchError.Text = ex.Message.ToString();
            }
        }