protected void btExportExcel_Click(object sender, EventArgs e)
        {
            //Export the GridView to Excel
            Common.ICommonDBHandler cdb = new Common.CommonDBHandler();

            //GridView whichgrid = new GridView();
            RadGrid whichgrid = new RadGrid();

            whichgrid.AllowPaging = false;
            string sort = ViewState["SearchResultSortExpression"].ToString() + ' ' + ViewState["SearchResultSortDirection"].ToString();

            gvSearchResults.Columns[13].Visible = true;

            whichgrid = gvSearchResults;

            Common.ExportToExcel.PrepareGridViewForExport(whichgrid);

            whichgrid.Columns[0].Visible  = false;
            whichgrid.Columns[13].Visible = true;
            whichgrid.Columns[14].Visible = false;
            whichgrid.Columns[20].Visible = false;
            whichgrid.Columns[21].Visible = false;
            whichgrid.Columns[22].Visible = false;
            whichgrid.Columns[23].Visible = false;
            whichgrid.Columns[24].Visible = false;

            whichgrid.MasterTableView.ExportToExcel();
        }
        protected void btnSendToRoute_Click(object sender, EventArgs e)
        {
            int fullcounter = 0;

            //move the job card routes into the meter reading routes tables and then redirect to Management console
            //first we need to check if all the instructions were filled in
            foreach (GridDataItem row in gvSearchResults.Items)
            {
                CheckBox chk = (CheckBox)row["MarkCHK"].Controls[0];
                //CheckBox tempbox = (CheckBox)row.FindControl("CheckBox1");
                Classes.IDBHandler             db   = new Classes.DBHandler();
                Common.ReadingsDetailDBHandler rddb = new Common.ReadingsDetailDBHandler();

                if (chk.Checked)
                {
                    //string statusdescr = gvSearchResults.SelectedItems[row.RowIndex].OwnerTableView.DataKeyValues[3].ToString();
                    int jobHeaderID = Convert.ToInt32(row.GetDataKeyValue("JobCardHeaderID").ToString());

                    //check instructions
                    int counter = 0;
                    counter = rddb.CheckInstructions(jobHeaderID);
                    if (counter == 0)
                    {
                        //all instructions have been inserted. move the routes.
                        Boolean correct = rddb.MoveJobCardsToRoutes(jobHeaderID);

                        //change contractID
                        int ContractID = rddb.GetWorkOrderContract();
                        Users_UserDetail                   uud   = (Users_UserDetail)Session["userDetails"];
                        Common.ICommonDBHandler            cdb   = new Common.CommonDBHandler();
                        UserContract                       uclst = cdb.GetUserContractList(uud).Where(x => x.EnableContract == true && x.ClientContract.ContractActive == true && x.ContractID == ContractID).FirstOrDefault();
                        Common.CommonTasks.UserContractDet ucd   = cdb.LoadUserContractDetByUserContractID(uclst.UserContractID);
                        Session["UserContractDet"] = ucd;

                        //Redirect to Management Console
                        Response.Redirect("RouteManagementConsole.aspx");
                    }
                    else
                    {
                        //there are missing instructions - dont allow.
                        lblError.Text    = "Cannot transfer routes, please ensure you have added instructions to each meter.";
                        lblError.Visible = true;
                    }
                    fullcounter++;
                }
            }

            if (fullcounter > 0)
            {
                gvSearchResults.Rebind();
            }
            else
            {
                lblError.Text      = "Please select at least one item to send.";
                lblError.ForeColor = System.Drawing.Color.Red;
                lblError.Visible   = true;
            }

            //Response.Redirect("RouteManagementConsole.aspx");
        }