protected void GridViewOrders_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                TableCell tc = e.Row.Cells[e.Row.Cells.Count - 1];

                DbDataRecord    ddr = e.Row.DataItem as DbDataRecord;
                URLPopUpControl upc = LoadControl("URLPopUpControl.ascx") as URLPopUpControl;

                upc.URLToPopup = "WebFormPopup.aspx?UC=OrderBase&OrderId=" + ddr.GetValue(0).ToString();
                upc.Text       = "Toon order";
                tc.Controls.Add(upc);
            }
        }
        private void GenerateOpenOrderButtons()
        {
            // add order lines
            for (int i = 0; i < GridViewOpenOrders.Rows.Count; i++)
            {
                URLPopUpControl upc = LoadControl("URLPopUpControl.ascx") as URLPopUpControl;

                upc.URLToPopup = "WebFormPopup.aspx?UC=EditOrderMaterials&OrderNr=" + GridViewOpenOrders.Rows[i].Cells[2].Text + "&ShowAlreadyDeliveredAmount=0&ShowSaveButton=0";
                upc.Text       = "Open ordermaterialen";

                int CellNr = GridViewOpenOrders.Rows[i].Cells.Count - 1;
                GridViewOpenOrders.Rows[i].Cells[CellNr].Controls.Clear();
                GridViewOpenOrders.Rows[i].Cells[CellNr].Controls.Add(upc);
            }
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if ((LinkField != "") && (UserControlForEditing != "") && (e.Row.DataItem != null))
            {
                TableCell tc = e.Row.Cells[0];

                DbDataRecord ddr = e.Row.DataItem as DbDataRecord;

                URLPopUpControl upc = LoadControl("URLPopUpControl.ascx") as URLPopUpControl;

                upc.URLToPopup = "WebFormPopup.aspx?UC=" + UserControlForEditing + "&Id=" + ddr[LinkField].ToString();
                upc.Text       = "Open";
                tc.Controls.Add(upc);
            }
        }
        protected void GridViewContractMaterials_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // add the edit button
            if (e.Row.DataItem != null)
            {
                TableCell tc = e.Row.Cells[e.Row.Cells.Count - 1];

                DbDataRecord    ddr = e.Row.DataItem as DbDataRecord;
                URLPopUpControl upc = LoadControl("URLPopUpControl.ascx") as URLPopUpControl;

                upc.URLToPopup = "WebFormPopup.aspx?UC=CustomerRelationContractMaterial&Id=" + ddr.GetValue(0).ToString();
                upc.Text       = "Toon contractmateriaal";
                tc.Controls.Add(upc);
            }
        }
        protected void GridViewRentedOutMaterials_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            DateTime EndDateRent;

            if (e.Row.DataItem != null)
            { // register the row id in the hint
                (e.Row.Cells[0].Controls[1] as CheckBox).ToolTip = (e.Row.DataItem as DbDataRecord).GetValue(0).ToString();
                (e.Row.Cells[0].Controls[1] as CheckBox).Checked = RentalNr > 0;

                // get the combobox
                ComboBox cbx = (e.Row.Cells[8].Controls[3] as ComboBox);

                // grab the possible new enddate from the grid
                EndDateRent = new DateTime(2100, 1, 1);
                try
                {
                    EndDateRent = Convert.ToDateTime((e.Row.DataItem as DbDataRecord).GetValue(4));
                    EndDateRent = Convert.ToDateTime((e.Row.Cells[4].Controls[0]).ToString()); // original value
                }
                catch { }

                ObjectQuery Results = ControlObjectContext.CreateQuery <RentalItem>(MaterialAvailableQuery,
                                                                                    new ObjectParameter("RentalType", (e.Row.DataItem as DbDataRecord).GetValue(2)),
                                                                                    new ObjectParameter("LocationId", (e.Row.DataItem as DbDataRecord).GetValue(1)),
                                                                                    new ObjectParameter("StartDate", (e.Row.DataItem as DbDataRecord).GetValue(3)),
                                                                                    new ObjectParameter("EndDate", EndDateRent),
                                                                                    new ObjectParameter("BorderEndDate", new DateTime(2100, 1, 1)));

                LoadComboBox(cbx, Results);

                URLPopUpControl upc = (e.Row.Cells[8].Controls[5] as URLPopUpControl);
                // get the corresponding RentalItemActivitySet
                Guid Temp = new Guid((e.Row.DataItem as DbDataRecord).GetValue(0).ToString());
//                RentalItemActivity ria = ControlObjectContext.RentalItemActivitySet.Where(m => m.Id == Temp).First<RentalItemActivity>();
                RentalItemActivity ria = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RentalItemActivitySet", "Id", Temp)) as RentalItemActivity;
                upc.Visible = false;
                if ((ria != null) && (ria.InvoiceLine != null))
                {
                    upc.Visible    = true;
                    upc.URLToPopup = "WebFormPopup.aspx?UC=InvoiceBase&Id=" + ria.InvoiceLine.Invoice.Id.ToString();
                }
            }
        }