コード例 #1
0
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            if (e.Item.OwnerTableView.IsItemInserted)
            {
                (e.Item.FindControl("cboTipoContrato") as RadComboBox).DataSource = (from c in Contexto.Clasificacion where c.Tipo == "Tipo Contrato" select new { c.IdClasificacion, c.Descripcion }).ToList();
                (e.Item.FindControl("cboTipoContrato") as RadComboBox).DataBind();

                (e.Item.FindControl("cboContratadoPor") as RadComboBox).DataSource = (from c in Contexto.Clasificacion where c.Tipo == "Contratado  por" select new { c.IdClasificacion, c.Descripcion }).ToList();
                (e.Item.FindControl("cboContratadoPor") as RadComboBox).DataBind();

                (e.Item.FindControl("cboContratista") as RadComboBox).DataSource = (from c in Contexto.Empresa orderby c.RazonSocial select new { c.IdEmpresa, c.RazonSocial }).ToList();
                (e.Item.FindControl("cboContratista") as RadComboBox).DataBind();

                (e.Item.FindControl("cboCategoria") as RadComboBox).DataSource = (from c in Contexto.Clasificacion where c.Tipo == "Categorias" select new { c.IdClasificacion, c.Descripcion }).ToList();
                (e.Item.FindControl("cboCategoria") as RadComboBox).DataBind();

                (e.Item.FindControl("cboArea") as RadComboBox).DataSource = (from c in Contexto.Clasificacion where c.Tipo == "Areas" orderby c.Codigo select new { c.IdClasificacion, c.Descripcion }).ToList();
                (e.Item.FindControl("cboArea") as RadComboBox).DataBind();
            }
        }

        if (e.Item.ItemType == GridItemType.EditFormItem)
        {
            if (e.Item.FindControl("cboContratista") != null)
            {
                if (e.Item.DataItem is TempContratos)
                {
                    TempContratos CurrentContrato = (TempContratos)e.Item.DataItem;

                    (e.Item.FindControl("cboTipoContrato") as RadComboBox).DataSource = (from c in Contexto.Clasificacion where c.Tipo == "Tipo Contrato" select new { c.IdClasificacion, c.Descripcion }).ToList();
                    (e.Item.FindControl("cboTipoContrato") as RadComboBox).DataBind();

                    (e.Item.FindControl("cboContratadoPor") as RadComboBox).DataSource = (from c in Contexto.Clasificacion where c.Tipo == "Contratado  por" select new { c.IdClasificacion, c.Descripcion }).ToList();
                    (e.Item.FindControl("cboContratadoPor") as RadComboBox).DataBind();

                    (e.Item.FindControl("cboCategoria") as RadComboBox).DataSource = (from c in Contexto.Clasificacion where c.Tipo == "Categorias" select new { c.IdClasificacion, c.Descripcion }).ToList();
                    (e.Item.FindControl("cboCategoria") as RadComboBox).DataBind();


                    (e.Item.FindControl("cboArea") as RadComboBox).DataSource = (from c in Contexto.Clasificacion where c.Tipo == "Areas" orderby c.Codigo select new { c.IdClasificacion, c.Descripcion }).ToList();
                    (e.Item.FindControl("cboArea") as RadComboBox).DataBind();


                    (e.Item.FindControl("cboContratista") as RadComboBox).DataSource = (from c in Contexto.Empresa orderby c.RazonSocial select new { c.IdEmpresa, c.RazonSocial }).ToList();
                    (e.Item.FindControl("cboContratista") as RadComboBox).DataBind();


                    (e.Item.FindControl("cboContratista") as RadComboBox).SelectedValue   = CurrentContrato.IdEmpresaContratista;
                    (e.Item.FindControl("cboTipoContrato") as RadComboBox).SelectedValue  = CurrentContrato.IdTipoContrato.ToString();
                    (e.Item.FindControl("cboCategoria") as RadComboBox).SelectedValue     = CurrentContrato.IdCategoria.ToString();
                    (e.Item.FindControl("cboArea") as RadComboBox).SelectedValue          = CurrentContrato.IdArea.ToString();
                    (e.Item.FindControl("cboContratadoPor") as RadComboBox).SelectedValue = CurrentContrato.IdContratadopor.ToString();
                }
            }
        }
    }
コード例 #2
0
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item)
        {
            //Entidades.Contrato contrato = EntityDataSourceExtensions.GetItemObject<Entidades.Contrato>(e.Item.DataItem);
            //contrato.ContratoEmpresas.Load();
            //if (contrato.ContratoEmpresas.Count > 0)
            //{
            //    Entidades.ContratoEmpresas CurrentContEmp = contrato.ContratoEmpresas.Where(w => w.EsContratista.Value).First();
            //    CurrentContEmp.EmpresaReference.Load();
            //    (e.Item.FindControl("LabelContratista") as Label).Text = CurrentContEmp.Empresa.RazonSocial;

            //    string cadenaSubCont = "";
            //    int i = 1;
            //    foreach (Entidades.ContratoEmpresas SubContratistas in contrato.ContratoEmpresas.Where(w => w.EsContratista.Value == false))
            //    {
            //        SubContratistas.EmpresaReference.Load();
            //        cadenaSubCont += "(" + i.ToString() + ") " + SubContratistas.Empresa.RazonSocial;
            //        i++;
            //    }

            //    (e.Item.FindControl("LblSubContratista") as Label).Text = cadenaSubCont;

            //}
        }
        else if (e.Item.ItemType == GridItemType.EditFormItem)
        {
            if (e.Item.FindControl("RadComboBoxContratista") != null)
            {
                if (e.Item.DataItem is TempContratos)
                {
                    TempContratos CurrentContrato = (TempContratos)e.Item.DataItem;

                    (e.Item.FindControl("RadComboBoxContratista") as RadComboBox).SelectedValue = CurrentContrato.IdEmpresaContratista;
                    (e.Item.FindControl("cboTipoContrato") as RadComboBox).SelectedValue        = CurrentContrato.IdTipoContrato.ToString();
                    (e.Item.FindControl("cboContratadoPor") as RadComboBox).SelectedValue       = CurrentContrato.IdContratadopor.ToString();

                    if (CurrentContrato.Categoria != null)
                    {
                        (e.Item.FindControl("cboCategoria") as RadComboBox).FindItemByText(CurrentContrato.Categoria).Selected = true;
                        //(e.Item.FindControl("cboCategoria") as RadComboBox).SelectedValue = CurrentContrato.Categoria.ToString();
                    }
                }
            }
        }
    }