Tengo un problema, empezando por la base de datos que tengo es la siguiente:
Nombre de la base be.mdb (Access 2003, aunque lo probe con MSSQL 2008)
Tablas en la base be.mbd:
- Ciudad
Columnas: Nombre_Ciudad(tipo de dato texto), CiudadID (tipo de dato texto)
- Estado
Columnas: Nombre_Estado (tipo de dato texto), EstadoID (tipo de dato texto)
Hice una relación entre EstadoID e CiudadID
La idea es que pueda hacer un combo de dos DwopDownList dependientes, el primero coloque el nombre del Estado y el segundo coloque automáticamente el nombre de la ciudad.
El código de la página .aspx tengo:
Código:
Y el código de la página .aspx.vb es:<%@ Page Language="VB" AutoEventWireup="false" CodeFile="combo1b.aspx.vb" Inherits="combo1b" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Página sin título</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
segundo
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
>>>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Código:
Hay un problema que no me aparece la dependencia en el segundo combo, si bien el debug no da errores hay algunas cosas que están mal y necesito ayuda, gracias! Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Partial Class combo1b
Inherits System.Web.UI.Page
Protected Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim objConn As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\RN\Documents\Visual Studio 2008\WebSites\WebSite1\App_Data\be.mdb")
Dim objAdapter As New Data.OleDb.OleDbDataAdapter("SELECT EstadoID, Nombre_Estado FROM Estado Order by Nombre_Estado Asc", objConn)
Dim objDataSet As New Data.DataSet()
objConn.Open()
objAdapter.Fill(objDataSet, "Estado")
DropDownList1.DataSource = objDataSet.Tables("Estado")
DropDownList1.DataTextField = "Nombre_Estado"
DropDownList1.DataValueField = "EstadoID"
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, "Seleccione un item")
DropDownList1.SelectedIndex = 0
objConn.Close()
Label1.Text = DropDownList1.SelectedItem.Value()
End If
End Sub
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
Dim objConn2 As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\RN\Documents\Visual Studio 2008\WebSites\WebSite1\App_Data\be.mdb")
Dim objAdapter2 As New Data.OleDb.OleDbDataAdapter("SELECT CiudadID, Nombre_Ciudad FROM Ciudad where CiudadID" & DropDownList1.SelectedItem.Value, objConn2)
Dim objDataSet2 As New Data.DataSet()
objConn2.Open()
objAdapter2.Fill(objDataSet2, "Ciudad")
DropDownList2.DataSource = objDataSet2.Tables("Ciudad")
DropDownList2.DataTextField = "Nombre_Ciudad"
DropDownList2.DataValueField = "CiudadID"
DropDownList2.DataBind()
DropDownList2.Items.Insert(0, "Seleccione un item")
DropDownList2.SelectedIndex = 0
Label2.Text = DropDownList1.SelectedItem.Value()
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
End Sub
End Class

