[ Foro de C# ]

DropdownList repite items

27-Jan-2015 20:35
Invitado (Fernando)
2 Respuestas

hola el problema es que mi dropdown repite los item que cargo :S
funciona perfectamente lo que quiero pero vuelve a repetirlos una vez que selecciono algun item


       protected void Page_Load(object sender, EventArgs e)
        {


            DropDownList1.DataSource = Factory.Clientes.GetGrupo();
            DropDownList1.DataValueField = "IdGrupo";
            DropDownList1.DataTextField = "IdGrupo";
            DropDownList1.AppendDataBoundItems = true;
            DropDownList1.AutoPostBack = true;
            DropDownList1.DataBind();
           
            }
        public void CargaDatos(int IdGrupo)
        {
                 
            GridView2.DataSource = Factory.Clientes.GetPerfiles(IdGrupo);
  
            GridView2.DataBind();
            
        }
     
        protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

            CargaDatos(int.Parse(DropDownList1.SelectedValue));

           // DropDownList1.Items.Clear();
         

    }
          
        }

    }


si desactivo el AppendDataBoundItems  deja de funcionar y no me carga los datos, intente limpiar y funciona pero ya no me vuelve a cargar los items, hay alguna solucion a esto, volver a cargarlos o evitar que se duplique?


28-Jan-2015 00:57
Nacho Cabanes (+83)

Te interesará borrar el contenido del DropDown antes de volver a cargar datos en él. Muchos componentes visuales tienen un método Clear que permite hacerlo.


03-Mar-2015 20:44
Invitado (Fernando)

ya quedo resuelto era un error

lo hice por separado y ya tengo avance


 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                CargaGrupos();
                CargaAreas(); 
            }
         CargaDatos(int.Parse(DropDownList1.SelectedValue), int.Parse(DropDownList2.SelectedValue));
        }
        private  void CargaGrupos()
        {
            DropDownList1.DataSource = Factory.Clientes.GetGrupos();
            DropDownList1.DataValueField = "IdGrupo";
            DropDownList1.DataTextField = "Descripcion";
            DropDownList1.AppendDataBoundItems = true;
            DropDownList1.AutoPostBack = true;
            DropDownList1.DataBind();
        }
        private  void CargaAreas()
        {
            DropDownList2.DataSource = Factory.Clientes.GetAreasResponsabilidad();
            DropDownList2.DataValueField = "IdAreaResponsabilidad";
            DropDownList2.DataTextField = "Descripcion";
            DropDownList2.AppendDataBoundItems = true;
            DropDownList2.AutoPostBack = true;
            DropDownList2.DataBind();
        }
        private void CargaDatos(int IdGrupo, int IdAreaResponsabilidad)
        {
            GridView2.DataSource = Factory.Clientes.GetPerfiles(IdGrupo, IdAreaResponsabilidad);
            GridView2.DataBind();








(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)