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

Problema Con .:.SelectionList.:. en ASP.NET Mobile

Estas en el tema de Problema Con .:.SelectionList.:. en ASP.NET Mobile en el foro de ASPX (.net) en Foros del Web. Hola que tal. Abrí un tema titulado " .:.Ayuda.:. Programación ASP.Net Mobile " y al parecer es una duda que no tiene solución. Encontré que ...
  #1 (permalink)  
Antiguo 18/12/2007, 08:32
 
Fecha de Ingreso: diciembre-2007
Mensajes: 19
Antigüedad: 16 años, 4 meses
Puntos: 0
Pregunta Problema Con .:.SelectionList.:. en ASP.NET Mobile

Hola que tal. Abrí un tema titulado ".:.Ayuda.:. Programación ASP.Net Mobile " y al parecer es una duda que no tiene solución. Encontré que para coordinar los datos de dos SelectionList en una misma página, lo que se necesita es colocar un Command para que se cargue el evento SelectedIndexChange, y eso es lo que hice, pero ahora surge un nuevo problema.

¿Cómo puedo obtener el valor que está seleccionado en el primer SelectionList para utilizarlo en una consulta SQL, para así obtener los datos que se colocarán en el segundo SelectionList? Esto es lo que tengo por ahora:


Protected Sub Agenda_Activate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox2.Text = Application("nombreusu")
If IsPostBack Then
Dim cn As New SqlConnection
cn.ConnectionString = "Server=TI-MAVA\SQLExpress; AttachDbFilename=C:\Archivos de programa\Microsoft SQL Server\MSSQL.1\MSSQL\Data\HERMOS-CRM.mdf; Database=HERMOS-CRM;Trusted_Connection=Yes;"
cn.Open()
Dim cmd As New SqlCommand
Dim qry As String
qry = "SELECT DIVISION FROM CLIENTES GROUP BY DIVISION ORDER BY DIVISION"
cmd.Connection = cn
cmd.CommandText = qry
Dim oDA As SqlDataAdapter
Dim oDS As New Data.DataSet()
Dim iCnt As Int32
Dim sDiv As String
Dim oItem As ListItem
oDA = New Data.SqlClient.SqlDataAdapter(cmd)
oDA.Fill(oDS)
SL1.Items.Clear()
With oDS.Tables(0)
For iCnt = 0 To .Rows.Count - 1
sDiv = .Rows(iCnt).Item("DIVISION").ToString()
oItem = New ListItem(sDiv)
SL1.Items.Add(oItem.ToString)
Next
End With
End If
End Sub


Protected Sub SL1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) 'Handles SL1.SelectedIndexChanged
If IsPostBack Then
Dim cn As New SqlConnection
cn.ConnectionString = "Server=TI-MAVA\SQLExpress; AttachDbFilename=C:\Archivos de programa\Microsoft SQL Server\MSSQL.1\MSSQL\Data\HERMOS-CRM.mdf; Database=HERMOS-CRM;Trusted_Connection=Yes;"
cn.Open()
Dim cmd As New SqlCommand
Dim qry As String
qry = "SELECT NOMBRE, CTEPRO FROM CLIENTES WHERE DIVISION= '" & SL1.Items(SL1.SelectedIndex).Text & "' "
cmd.Connection = cn
cmd.CommandText = qry
Dim oDA As SqlDataAdapter
Dim oDS As New Data.DataSet()
Dim iCnt As Int32
Dim sName As String
Dim oItem As ListItem
Dim sKey As String
oDA = New Data.SqlClient.SqlDataAdapter(cmd)
oDA.Fill(oDS)
SL2.Items.Clear()
With oDS.Tables(0)
For iCnt = 0 To .Rows.Count - 1
sName = .Rows(iCnt).Item("NOMBRE").ToString()
sKey = .Rows(iCnt).Item("CTEPRO").ToString()
oItem = New ListItem(sName, sKey)
SL2.Items.Add(oItem.ToString)
Next
End With
cn.Close()
End If
End Sub

Pero no funciona, y es que el valor de SelectedIndex siempre está en -1. Encontré otras formas en distintos foros, indican que se puede utilizar lo siguiente: SL1.Selection.Value o SL1.Selection.Text, pero tampoco funcionan, en estos, el error es que el valor de Selection siempre es Nothing. ¿Por qué el valor de SelectedIndex siempre es -1?
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 08:45.