Ver Mensaje Individual
  #5 (permalink)  
Antiguo 10/04/2010, 20:30
Avatar de jsrc1990
jsrc1990
 
Fecha de Ingreso: enero-2009
Mensajes: 95
Antigüedad: 15 años, 3 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