Si cuando selecciono Estado, ya ajuro pide seleccionarr ciudad y cuando selecciona ciudad ajuro pide seleccionar ubicacion, los drop estan enlazados entre si
y gracias por la acotacion final esa esta mejor que la que uso
| ||||
La varible q te he pueto antes (viewstate) es para q en el buton buscar saber d alguna manera por donde tirar,si la busqueda debe ser un filtro por la ubicaion,o si por el contrario la ubicaion no le interesaq sea un filtro y simplemete dese a ver las agencias q tiene unos servecios en concreto de ahi if viewstate("")=si then Dim ds As DataSet Dim strSql As String Dim MyConnection As SqlConnection Dim MyCommand As SqlDataAdapter strSql = " SELECT " For j = 0 To Check1.Items.Count - 1 If Check1.Items(j).Selected Then ' Entra si esta seleccionado strSql += " " & Check1.Items(j).value & ", " end if Next strSql += " Agencia.Identificador as Agencia, Agencia.Direccion as Direccion, Agencia.Telefono as Telefono, Agencia.Cajero_Automatico as Cajero_Automatico, Agencia.Autobanco as Autobanco, Agencia.Taquilla_Externa as Taquilla_Externa, Agencia.Estacionamiento as Agencia_Estacionamiento, Estado.Nombre_Estado as Estado, Ciudad.Nombre_Ciudad as Ciudad, Ubicacion.Descripcion as Ubicación From Agencia, Estado, Ciudad, Ubicacion " strSql += " WHERE Agencia.EstadoID=Estado.EstadoID" strSql += " AND Agencia.CiudadID=Ciudad.CiudadID" strSql += " AND Agencia.UbicacionID=Ubicacion.UbicacionID" strSql += " AND Agencia.EstadoID=" &DropDownList1.SelectedItem.Value strSql += " AND Agencia.CiudadID=" &DropDownList2.SelectedItem.Value strSql += " AND Agencia.UbicacionID=" &DropDownList3.SelectedItem.Value else 'podria ser si te entendi lo q kerias(q fuera el filtro los servicios) strSql += "Select Agencia.Identificador as Agencia, Agencia.Direccion as Direccion, Agencia.Telefono as Telefono, Agencia.Cajero_Automatico as Cajero_Automatico, Agencia.Autobanco as Autobanco, Agencia.Taquilla_Externa as Taquilla_Externa, Agencia.Estacionamiento as Agencia_Estacionamiento, Estado.Nombre_Estado as Estado, Ciudad.Nombre_Ciudad as Ciudad, Ubicacion.Descripcion as Ubicación From Agencia, Estado, Ciudad, Ubicacion " strSql += " WHERE Agencia.EstadoID=Estado.EstadoID" strSql += " AND Agencia.CiudadID=Ciudad.CiudadID" strSql += " AND Agencia.UbicacionID=Ubicacion.UbicacionID" For j = 0 To Check1.Items.Count - 1 If Check1.Items(j).Selected Then ' Entra si esta seleccionado strSql += " AND " & Check1.Items(j).value & "='si' " end if Next end if y esa viewstate le pondrias a si en el evento q salta cuando elige un estado |
| ||||
Oye hay algo que me confunde, llamo al viewstate desde el evento DropDownList1_SelectedIndexChanged(ese el evento que me permite cargar el contenido del 2do drop) es a eso que te refieres y de ser asi? llamo asi viewstate("")=si a que te refieres cuando dentro del viewstate no pones nada me refiero asi viewstate("")? |
| ||||
Neivan otra consulta, ¿El valor del lado de la igualdad de la variable de session tiene que se igual a Si o No, porque? no entiendo porque. Veras todo el page load de la pag lo agregue igual a no. De la siguiente manera Sub Page_Load(Sender As Object, E As EventArgs) viewstate("MbpA")= "no" If Not IsPostBack Dim ds As DataSet Dim MyConnection As SqlConnection Dim MyCommand As SqlDataAdapter ds = New DataSet () MyConnection = New SqlConnection("SERVER=MDS01; DATABASE=be; INTEGRATED SECURITY=false;PASSWORD=sa;USER=sa") MyCommand = New SqlDataAdapter ("select EstadoID, Nombre_Estado from Estado" , MyConnection) MyCommand.Fill(ds,"Estado") DropDownList1.DataSource = ds.Tables("Estado").DefaultView DropDownList1.DataTextField = "Nombre_Estado" DropDownList1.DataValueField ="EstadoID" DropDownList1.DataBind() DropDownList1.Items.Insert(0, "Seleccione un item") DropDownList1.SelectedIndex = 0 end if end sub No me queda claro si agregarlo dentro del bloque If not ispostback ademas lo agregue en el evento DropDownList1_SelectedIndexChanged Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) viewstate("MbpA")= "si" 'Cargo drop2 end sub luego finalmente el control buton Dim i As Int32 Dim j As Int32 Dim strSql As String if viewstate("MbpA")= "si" 'Cargo el combo busqueda For i = 0 to Check1.Items.Count-1 if Check1.selectedindex=-1 Then Iblmessage.Text = "Es necesario que seleccione un servicio" Else If Check1.Items(i).Selected Then Iblmessage.Text="" Dim ds As DataSet Dim MyConnection As SqlConnection Dim MyCommand As SqlDataAdapter strSql = " SELECT " For j = 0 To Check1.Items.Count - 1 If Check1.Items(j).Selected Then ' Entra si esta seleccionado strSql += " " & Check1.Items(j).value & ", " end if Next strSql += " Agencia.Agencia as Agencia, Agencia.Direccion as Direccion, Agencia.Telefono as Telefono, Estado.Nombre_Estado as Estado, Ciudad.Nombre_Ciudad as Ciudad, Ubicacion.Descripcion as Ubicación From Agencia, Estado, Ciudad, Ubicacion " strSql += " WHERE Agencia.EstadoID=Estado.EstadoID" strSql += " AND Agencia.CiudadID=Ciudad.CiudadID" strSql += " AND Agencia.UbicacionID=Ubicacion.UbicacionID" strSql += " AND Agencia.EstadoID=" &DropDownList1.SelectedItem.Value strSql += " AND Agencia.CiudadID=" &DropDownList2.SelectedItem.Value strSql += " AND Agencia.UbicacionID=" &DropDownList3.SelectedItem.Value Else if viewstate("MbpA")= "no" strSql += "Select Agencia.Identificador as Agencia, Agencia.Direccion as Direccion, Agencia.Telefono as Telefono, Agencia.Cajero_Automatico as Cajero_Automatico, Agencia.Autobanco as Autobanco, Agencia.Taquilla_Externa as Taquilla_Externa, Agencia.Estacionamiento as Agencia_Estacionamiento, Estado.Nombre_Estado as Estado, Ciudad.Nombre_Ciudad as Ciudad, Ubicacion.Descripcion as Ubicación From Agencia, Estado, Ciudad, Ubicacion " strSql += " WHERE Agencia.EstadoID=Estado.EstadoID" strSql += " AND Agencia.CiudadID=Ciudad.CiudadID" strSql += " AND Agencia.UbicacionID=Ubicacion.UbicacionID" For j = 0 To Check1.Items.Count - 1 If Check1.Items(j).Selected Then ' Entra si esta seleccionado strSql += " AND " & Check1.Items(j).value & "='si' " end if Next end if next end if End Sub |
| ||||
De esta manera siempre te entrara en e lno,por que en el page load debes poner la viewstate dentro del if Sub Page_Load(Sender As Object, E As EventArgs) If Not IsPostBack viewstate("MbpA")= "no" ... end fi esto es por q el page load se carga simpre q das a un boton,cdo tecleas por ejemplo el boton de busqueda primero recarga la pagina,va al page load y hace lo q pone (lo q esta dentro del if not ispostback solo la priemra vez) y luego ejecuta el codigo que tengas en el boton... como lo tenias haya pasado lo que haya pasado te pondra la viewstate("MbpA") a no.... que pongas q la viewstate sea igual a si o a no es como si pones si es pepe o juan,es para controlar d elaguna manera si ha elegido un estado,pero se podria por ejemplo hacer con un check box por ejemplo en el q tenga 2 opciones para elegir (las dos tipos de busqueda,por ubicacion,o la nueva q es nada de ubicacion y por servicio) La viewstate no es una variable d esession sino de "pagina" mantiene el valor en esta pagina hasta q te vas a otra... |
| ||||
ya entendi, ![]() cuando uno los define lo hace asi? viewstate("amarilla")= "si" |
| ||||
si,con eso te la crea,compruba donde te entra poniendo un label de control,es decir un label q cdo de al boton de busqueda el la parte de que comparas si la viewstate es si ,si entra,q ponga el label.text="si",si si entra en la no q la ponga a no.Asi sabras si te ha emtrado donde te tenia q entrar,y podras saber si el fallo es de la variable q no tiene el valor q debiera tener o e l problema viene por otro lado. Recuerda q la la viewstate("MbpA")= "no" ponla dentro del if not ispostback |
| ||||
No comprendo bien tu sugerenia de colocar un lable que es cdo para ti? "es decir un label q cdo de al boton" Bueno y si entendi como creo que es yo lo hize asi Sub Button1_Click(sender As Object, e As EventArgs) Dim i As Int32 Dim j As Int32 Dim strSql As String if viewstate("MbpA")= "si" then .....' Cargo codigo normal, con la seleccion de los drop Else if viewstate("MbpA")= "no" ....Cargo codijo si la seleccionde drops end if next end if If viewstate("MbpA")= "si" then Iblmessage.Text = CStr(ViewState("MbpA")) end if entonces mira lo que pasa cuando corro la aplicacion y no selecciono lo drop (Estado, ciudad, y ubicacion) no me muestra nada ni siquiera el data grid vacio Cuando selecciono algo en los drop de igual manera no me muestra nada pero el label me devuelve el valor si ![]() |
| ||||
Este es el codigo del boton Sub Button1_Click(sender As Object, e As EventArgs) Dim i As Int32 Dim j As Int32 Dim strSql As String if viewstate("MbpA")= "si" then 'Cargo el combo busqueda For i = 0 to Check1.Items.Count-1 if Check1.selectedindex=-1 Then Iblmessage.Text = "Es necesario que seleccione un servicio" Else If Check1.Items(i).Selected Then Iblmessage.Text="" Dim ds As DataSet Dim MyConnection As SqlConnection Dim MyCommand As SqlDataAdapter strSql = " SELECT " For j = 0 To Check1.Items.Count - 1 If Check1.Items(j).Selected Then strSql += " " & Check1.Items(j).value & ", " end if Next strSql += " Agencia.Agencia as Agencia, Agencia.Direccion as Direccion, Agencia.Telefono as Telefono, Estado.Nombre_Estado as Estado, Ciudad.Nombre_Ciudad as Ciudad, Ubicacion.Descripcion as Ubicación From Agencia, Estado, Ciudad, Ubicacion " strSql += " WHERE Agencia.EstadoID=Estado.EstadoID" strSql += " AND Agencia.CiudadID=Ciudad.CiudadID" strSql += " AND Agencia.UbicacionID=Ubicacion.UbicacionID" strSql += " AND Agencia.EstadoID=" &DropDownList1.SelectedItem.Value strSql += " AND Agencia.CiudadID=" &DropDownList2.SelectedItem.Value strSql += " AND Agencia.UbicacionID=" &DropDownList3.SelectedItem.Value Else if viewstate("MbpA")= "no" strSql += "Select Agencia.Agencia as Agencia, Agencia.Direccion as Direccion, Agencia.Telefono as Telefono, Agencia.Cajero_Automatico as Cajero_Automatico, Agencia.Autobanco as Autobanco, Agencia.Taquilla_Externa as Taquilla_Externa, Agencia.Estacionamiento as Agencia_Estacionamiento, Estado.Nombre_Estado as Estado, Ciudad.Nombre_Ciudad as Ciudad, Ubicacion.Descripcion as Ubicación From Agencia, Estado, Ciudad, Ubicacion " strSql += " WHERE Agencia.EstadoID=Estado.EstadoID" strSql += " AND Agencia.CiudadID=Ciudad.CiudadID" strSql += " AND Agencia.UbicacionID=Ubicacion.UbicacionID" For j = 0 To Check1.Items.Count - 1 If Check1.Items(j).Selected Then ' Entra si esta seleccionado strSql += " AND " & Check1.Items(j).value & "='si' " end if Next end if next end if if viewstate("MbpA")= "si" then Iblmessage.Text = CStr(ViewState("MbpA")) end if End Sub |
| ||||
Pues dejame decirte que viste algo fundamental, quite el enlaze del data grid para hacerlo en otro parte y lamarlo desde alli como BinGrid(), y pues nunca agregue el llamado en el codigo del boton ![]() ![]() Entonces estariamos hablando de algo asi Sub Button1_Click(sender As Object, e As EventArgs) Dim i As Int32 Dim j As Int32 Dim strSql As String if viewstate("MbpA")= "si" then 'Cargo el combo busqueda For i = 0 to Check1.Items.Count-1 if Check1.selectedindex=-1 Then Iblmessage.Text = "Es necesario que seleccione un servicio" Else If Check1.Items(i).Selected Then Iblmessage.Text="" strSql = " SELECT " For j = 0 To Check1.Items.Count - 1 If Check1.Items(j).Selected Then ' Entra si esta seleccionado strSql += " " & Check1.Items(j).value & ", " end if Next strSql += " Agencia.Agencia as Agencia, Agencia.Direccion as Direccion, Agencia.Telefono as Telefono, Estado.Nombre_Estado as Estado, Ciudad.Nombre_Ciudad as Ciudad, Ubicacion.Descripcion as Ubicación From Agencia, Estado, Ciudad, Ubicacion " strSql += " WHERE Agencia.EstadoID=Estado.EstadoID" strSql += " AND Agencia.CiudadID=Ciudad.CiudadID" strSql += " AND Agencia.UbicacionID=Ubicacion.UbicacionID" strSql += " AND Agencia.EstadoID=" &DropDownList1.SelectedItem.Value strSql += " AND Agencia.CiudadID=" &DropDownList2.SelectedItem.Value strSql += " AND Agencia.UbicacionID=" &DropDownList3.SelectedItem.Value BindGrid() Else if viewstate("MbpA")= "no" strSql += "Select Agencia.Agencia as Agencia, Agencia.Direccion as Direccion, Agencia.Telefono as Telefono, Agencia.Cajero_Automatico as Cajero_Automatico, Agencia.Autobanco as Autobanco, Agencia.Taquilla_Externa as Taquilla_Externa, Agencia.Estacionamiento as Agencia_Estacionamiento, Estado.Nombre_Estado as Estado, Ciudad.Nombre_Ciudad as Ciudad, Ubicacion.Descripcion as Ubicación From Agencia, Estado, Ciudad, Ubicacion " strSql += " WHERE Agencia.EstadoID=Estado.EstadoID" strSql += " AND Agencia.CiudadID=Ciudad.CiudadID" strSql += " AND Agencia.UbicacionID=Ubicacion.UbicacionID" For j = 0 To Check1.Items.Count - 1 If Check1.Items(j).Selected Then ' Entra si esta seleccionado strSql += " AND " & Check1.Items(j).value & "='si' " end if Next end if BindGrid() next end if End Sub Sub BindGrid() Dim strSql As String Dim ds As DataSet Dim MyConnection As SqlConnection Dim MyCommand As SqlDataAdapter MyConnection = New SqlConnection("SERVER=MDS01; DATABASE=be; INTEGRATED SECURITY=false;PASSWORD=sa;USER=sa") MyCommand = New SqlDataAdapter(strSql, MyConnection) ds = new DataSet() MyCommand.Fill(ds, "Agencia") MyDataGrid.DataSource=ds.Tables("Agencia").Default View MyDataGrid.DataBind() end sub De esta manera no muesta nada cuando no seleccione los combos y cuando los selecciono da un error de ExecuteReader: CommandText property has not been initialized Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: ExecuteReader: CommandText property has not been initialized Source Error: Line 147: MyCommand.Fill(ds, "Agencia") quizas deba hacer dos eventos bingrid uno para cuando se seleccione y otro para cuando no, pero podria haberte jurado que asi funcionaria |
| ||||
sigiendo con los milagros de la programcion te he visto otra en tu codigo,como coge el strSql del metodo valor alguno????? define el metodo asi BindGrid(strSql as string) y cdo le llames llamalo :BindGrid(strSql) kedaria asi Sub Bind (GridstrSql as string) '----- Dim strSql As String----esto kitalo lo demas igual Dim ds As DataSet Dim MyConnection As SqlConnection Dim MyCommand As SqlDataAdapter MyConnection = New SqlConnection("SERVER=MDS01; DATABASE=be; INTEGRATED SECURITY=false;PASSWORD=sa;USER=sa") MyCommand = New SqlDataAdapter(strSql, MyConnection) ds = new DataSet() MyCommand.Fill(ds, "Agencia") MyDataGrid.DataSource=ds.Tables("Agencia").Default View MyDataGrid.DataBind() end sub asi en cada momento le pasas la consulta quieras q te enlace |
| ||||
Pues, segui tus recomendaciones y el codigo quedo asi Sub Button1_Click(sender As Object, e As EventArgs) Dim i As Int32 Dim j As Int32 Dim strSql As String For i = 0 to Check1.Items.Count-1 if Check1.selectedindex=-1 Then Iblmessage.Text = "Es necesario que seleccione un servicio" Else If Check1.Items(i).Selected Then Iblmessage.Text="" if viewstate("MbpA")= "si" then 'Cargo el combo busqueda strSql = " SELECT " For j = 0 To Check1.Items.Count - 1 If Check1.Items(j).Selected Then ' Entra si esta seleccionado strSql += " " & Check1.Items(j).value & ", " end if Next strSql += " Agencia.Agencia as Agencia, Agencia.Direccion as Direccion, Agencia.Telefono as Telefono, Estado.Nombre_Estado as Estado, Ciudad.Nombre_Ciudad as Ciudad, Ubicacion.Descripcion as Ubicación From Agencia, Estado, Ciudad, Ubicacion " strSql += " WHERE Agencia.EstadoID=Estado.EstadoID" strSql += " AND Agencia.CiudadID=Ciudad.CiudadID" strSql += " AND Agencia.UbicacionID=Ubicacion.UbicacionID" strSql += " AND Agencia.EstadoID=" &DropDownList1.SelectedItem.Value strSql += " AND Agencia.CiudadID=" &DropDownList2.SelectedItem.Value strSql += " AND Agencia.UbicacionID=" &DropDownList3.SelectedItem.Value BindGrid(strSql) Else if viewstate("MbpA")= "no" strSql += "Select Agencia.Agencia as Agencia, Agencia.Direccion as Direccion, Agencia.Telefono as Telefono, Agencia.Cajero_Automatico as Cajero_Automatico, Agencia.Autobanco as Autobanco, Agencia.Taquilla_Externa as Taquilla_Externa, Agencia.Estacionamiento as Agencia_Estacionamiento, Estado.Nombre_Estado as Estado, Ciudad.Nombre_Ciudad as Ciudad, Ubicacion.Descripcion as Ubicación From Agencia, Estado, Ciudad, Ubicacion " strSql += " WHERE Agencia.EstadoID=Estado.EstadoID" strSql += " AND Agencia.CiudadID=Ciudad.CiudadID" strSql += " AND Agencia.UbicacionID=Ubicacion.UbicacionID" For j = 0 To Check1.Items.Count - 1 If Check1.Items(j).Selected Then ' Entra si esta seleccionado strSql += " AND " & Check1.Items(j).value & "='si' " end if Next end if BindGrid(strSql) end if next End Sub Sub BindGrid(strSql as string) Dim ds As DataSet Dim MyConnection As SqlConnection Dim MyCommand As SqlDataAdapter MyConnection = New SqlConnection("SERVER=MDS01; DATABASE=be; INTEGRATED SECURITY=false;PASSWORD=sa;USER=sa") MyCommand = New SqlDataAdapter(strSql, MyConnection) ds = new DataSet() MyCommand.Fill(ds, "Agencia") MyDataGrid.DataSource=ds.Tables("Agencia").Default View MyDataGrid.DataBind() End Sub Pasan dos cosas interesantes 1.- Cuando selecciono servicio y no los drops, me muestra el grid con los nombre de los campos pero sin informacion 2.-Cuando selecciono sevicio y los drop me muestra el grid con los campos y la informacion ¿Qué te parece? |
| ||||
Y acabo de descubir un atrecera cosa Cuando selecciono un solo servicio y no selecciono los drop si hace la consulta y me muestra las agencias que que prestan ese servico por ubicacion geografica Ahora estoy mas cerca de conseguir mi fin ![]() Muchas gracias |