Foros del Web » Programando para Internet » ASPX (.net) »

Funciones para llenado DropDownList

Estas en el tema de Funciones para llenado DropDownList en el foro de ASPX (.net) en Foros del Web. Hola, Alguien conoce alguna función para llenar varios dropdownlist??? pero debo utilizar tres capas. Saludos!! Atte ISA...
  #1 (permalink)  
Antiguo 09/04/2010, 16:11
 
Fecha de Ingreso: marzo-2010
Mensajes: 26
Antigüedad: 14 años, 1 mes
Puntos: 0
Pregunta Funciones para llenado DropDownList

Hola,
Alguien conoce alguna función para llenar varios dropdownlist??? pero debo utilizar tres capas.

Saludos!!

Atte
ISA
  #2 (permalink)  
Antiguo 09/04/2010, 17:08
Avatar de okhosting  
Fecha de Ingreso: diciembre-2009
Ubicación: México
Mensajes: 66
Antigüedad: 14 años, 3 meses
Puntos: 0
Respuesta: Funciones para llenado DropDownList

Si puedes cargar un DataTable con tus datos, entonces nada mas le asignas al DropDownList.DataSource = tuDataTable, luego le asignas el DataTextField con el campo que se mostrara como texto, el DataValueField con el campo que tenga la llave primaria y le das DataBind()

Suerte!
  #3 (permalink)  
Antiguo 09/04/2010, 17:29
 
Fecha de Ingreso: marzo-2010
Mensajes: 26
Antigüedad: 14 años, 1 mes
Puntos: 0
Respuesta: Funciones para llenado DropDownList

si.,. y le tengo que pasar mis parametros de procedimiento almacenado y los nombres de los campos.. pero no se como :(!
  #4 (permalink)  
Antiguo 10/04/2010, 17:38
Avatar de okhosting  
Fecha de Ingreso: diciembre-2009
Ubicación: México
Mensajes: 66
Antigüedad: 14 años, 3 meses
Puntos: 0
Respuesta: Funciones para llenado DropDownList

Al dropdown no le pasas parametros, mas bien tienes que seguir estos pasos:

1- Llenar un DataTable con tus datos (aqui es donde usas los parametros de un store procedure)

2- Una vez que tienes lod atso en el datatable, sigues los pasos que te indique antes

Para que puedas ejecutar el store procedure tienes las instrucciones que te pase en el otro tema http://www.forosdelweb.com/f78/proce...enados-795815/

Es decir primero ejecutas el store procedure y llenas un DataTable, y ya despues con el DataTable llenas el dropdown

Suerte!
  #5 (permalink)  
Antiguo 10/04/2010, 20:30
Avatar de jsrc1990  
Fecha de Ingreso: enero-2009
Mensajes: 95
Antigüedad: 15 años, 2 meses
Puntos: 0
De acuerdo Respuesta: Funciones para llenado DropDownList

Él a lo que se refiere es a esto, que pena que no te pude escribir en el otro post que hicistes en el de hannah_banana ya que donde trabajo tienen los foros bloqueados y aunque me la safe XD con ultrasurf... tuve problemas, aqui va:

Tienes 2 Posibilidades:

Crear un Metodo la cual cargue de UN DropDownList (El que tu quieras) al invocar el susodicho:

Código ASP:
Ver original
  1. Llenar_DropDownLists(TuDropDownList1, "Tu_Campo_Texto", "Tu_Campo_Valor")
  2. Llenar_DropDownLists(TuDropDownList2, "Tu_Campo_Texto", "Tu_Campo_Valor")
  3. Llenar_DropDownLists(TuDropDownList3, "Tu_Campo_Texto", "Tu_Campo_Valor")

Código ASP:
Ver original
  1. Protected Sub Llenar_DropDownLists(ByVal DropDownListLlenador As DropDownList, ByVal Texto As String, ByVal Valor As String)
  2. DropDownListLlenador.DataSource = "Tu_Source"
  3. DropDownListLlenador.DataTextField = Texto
  4. DropDownListLlenador.DataValueField = Valor
  5. DropDownListLlenador.DataBind()
  6. End Sub

o bien crear un Metodo la cual contenga como parametro un Array de Dropdownlist's la cual te cargue VARIOS a la vez:

Código ASP:
Ver original
  1. Llenar_DropDownLists(New DropDownList() {TuDropDownList1, TuDropDownList2, TuDropDownList3}, New String() {"Tu_Texto_DropDownList1", "Tu_Texto_DropDownList2", "Tu_Texto_DropDownList3"}, New String() {"TuValor_DropDownList1", "TuValor_DropDownList2", "TuValor_DropDownList3"})

Código ASP:
Ver original
  1. Protected Sub Llenar_DropDownLists(ByVal DropDownListLlenador() As DropDownList, ByVal Textos() As String, ByVal Valores() As String)
  2. For Indice = 0 To DropDownListLlenador.Length - 1
  3. DropDownListLlenador(Indice).DataSource = "Tu_Source"
  4. DropDownListLlenador(Indice).DataTextField = Textos(Indice)
  5. DropDownListLlenador(Indice).DataValueField = Valores(Indice)
  6. DropDownListLlenador(Indice).DataBind()
  7. Next
  8. End Sub

Si quieres ademas que te retorne un valor que diga cuantos items se crearon haz una function asi:

Código ASP:
Ver original
  1. Llenar_DropDownLists(TuDropDownList1, "Tu_Campo_Texto", "Tu_Campo_Valor")
  2. Llenar_DropDownLists(TuDropDownList2, "Tu_Campo_Texto", "Tu_Campo_Valor")
  3. Llenar_DropDownLists(TuDropDownList3, "Tu_Campo_Texto", "Tu_Campo_Valor")

Código ASP:
Ver original
  1. Protected Function Llenar_DropDownLists(ByVal DropDownListLlenador As DropDownList, ByVal Texto As String, ByVal Valor As String) As Integer
  2. DropDownListLlenador.DataSource = "Tu_Source"
  3. DropDownListLlenador.DataTextField = Texto
  4. DropDownListLlenador.DataValueField = Valor
  5. DropDownListLlenador.DataBind()
  6. Return DropDownListLlenador.Items.Count
  7. End Function

y en Array que retorne el numero de items de cada dropdownlist:

Código ASP:
Ver original
  1. Llenar_DropDownLists(New DropDownList() {TuDropDownList1, TuDropDownList2, TuDropDownList3}, New String() {"Tu_Texto_DropDownList1", "Tu_Texto_DropDownList2", "Tu_Texto_DropDownList3"}, New String() {"TuValor_DropDownList1", "TuValor_DropDownList2", "TuValor_DropDownList3"})

Código ASP:
Ver original
  1. Protected Function Llenar_DropDownLists(ByVal DropDownListLlenador() As DropDownList, ByVal Textos() As String, ByVal Valores() As String) As Integer()
  2. Dim Numeros_de_Items(DropDownListLlenador.Length - 1) As Integer
  3. For Indice = 0 To DropDownListLlenador.Length - 1
  4. DropDownListLlenador(Indice).DataSource = "Tu_Source"
  5. DropDownListLlenador(Indice).DataTextField = Textos(Indice)
  6. DropDownListLlenador(Indice).DataValueField = Valores(Indice)
  7. DropDownListLlenador(Indice).DataBind()
  8. Numeros_de_Items(Indice) = DropDownListLlenador(Indice).Items.Count
  9. Next
  10. Return Numeros_de_Items
  11. End Function

Espero haberte ayudado

Jsrc1990
  #6 (permalink)  
Antiguo 12/04/2010, 10:45
 
Fecha de Ingreso: marzo-2010
Mensajes: 26
Antigüedad: 14 años, 1 mes
Puntos: 0
Respuesta: Funciones para llenado DropDownList

Perfecto!!!

Voy a implementarlo muchas gracias por su apoyo.

Saludos!!!



Atte
ISA

Etiquetas: dropdownlist, funciones, aspx
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:25.