Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/02/2005, 08:23
Avatar de Sayra
Sayra
 
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 19 años, 6 meses
Puntos: 1
problema con DropDownlist dependientes

Hola, en esta aplicacion sencilla tengo tres dropdownlist que enlazan a tres tablas distintas de una base de datos sql server, el problema es que cuando los enlazo entre
veran cuando en el 1er drop seleccio un estado en 2do drop solo me muestra las ciudades correspondientes a ese estado, pero cuando selccionar alguna ciudad para el combo de ubicaciones entonces , no permite selccionar, ojala puedan aconsejarme algo de seguro tengo un error en el codijo y no lo veo. Abajo dejo el código. Gracias por todo

<%@ Page language="VB" Codebehind="Prueba10mil.aspx.cs" AutoEventWireup="True" Inherits="Rainbow.DesktopModules.Agencia.Prueba10m il" debug=true%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<script language="vb" runat="server">

Sub Page_Load(Sender As Object, E As EventArgs)

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()

end if
BindCiudad()
end sub

public Sub BindCiudad()


Dim dc As DataSet
Dim MyConnection2 As SqlConnection
Dim MyCommand2 As SqlDataAdapter

dc = New DataSet ()
MyConnection2 = New SqlConnection("SERVER=MDS01; DATABASE=be; INTEGRATED SECURITY=false;PASSWORD=sa;USER=sa")

MyCommand2 = New SqlDataAdapter ("select CiudadID, Nombre_Ciudad from Ciudad Where EstadoID=" &DropDownList1.SelectedItem.Value, MyConnection2)
MyCommand2.Fill(dc,"Ciudad")

DropDownList2.DataSource = dc.Tables("Ciudad").DefaultView
DropDownList2.DataTextField = "Nombre_Ciudad"
DropDownList2.DataValueField ="CiudadID"
DropDownList2.DataBind()
BindUbicacion()
end sub

public Sub BindUbicacion()

Dim du As DataSet
Dim MyConnection3 As SqlConnection
Dim MyCommand3 As SqlDataAdapter

du = New DataSet ()
MyConnection3 = New SqlConnection("SERVER=MDS01; DATABASE=be; INTEGRATED SECURITY=false;PASSWORD=sa;USER=sa")

MyCommand3 = New SqlDataAdapter("select UbicacionID, Descripcion from Ubicacion Where CiudadID=" &DropDownList2.SelectedItem.Value, MyConnection3)
MyCommand3.Fill(du,"Ubicacion")

DropDownList3.DataSource = du.Tables("Ubicacion").DefaultView
DropDownList3.DataTextField = "Descripcion"
DropDownList3.DataValueField ="UbicacionID"
DropDownList3.DataBind()

end sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

BindCiudad()

End Sub

Private Sub DropDownList2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
BindUbicacion()
End Sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<TABLE height="635" cellSpacing="0" cellPadding="0" width="137" border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD width="137" height="635">
<form id="Form1" method="post" runat="server">
<TABLE height="120" cellSpacing="0" cellPadding="0" width="623" border="0" ms_2d_layout="TRUE">
<TR vAlign="top">
<TD width="10" height="15"></TD>
<TD width="613"></TD>
</TR>
<TR vAlign="top">
<TD height="41"></TD>
<TD>
<P>Estado:
<asp:dropdownlist id="DropDownList1" BackColor="AliceBlue" Font-Names="Arial" ForeColor="Black" AutoPostBack="True"
Runat="server"></asp:dropdownlist></P>
</TD>
</TR>
<TR vAlign="top">
<TD height="41"></TD>
<TD>
<P>Ciudad:
<asp:dropdownlist id="Dropdownlist2" BackColor="AliceBlue" AutoPostBack="True" Runat="server"></asp:dropdownlist></P>
</TD>
</TR>
<TR vAlign="top">
<TD height="23"></TD>
<TD>
<P>Ubicacion:
<asp:dropdownlist id="Dropdownlist3" BackColor="AliceBlue" AutoPostBack="True" Runat="server"></asp:dropdownlist></P>
</TD>
</TR>
</TABLE>
</form>
</TD>
</TR>
</TABLE>
</body>
</HTML>