
10/02/2005, 15:00
|
 | | | Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 20 años, 3 meses Puntos: 1 | |
Hola Neivan este es el codigo de la aplicacion que estoy construyendo estoy usando tre drropdownlist que se conectan a tres tablas distintas estado, ciudad y ubicacion. El enlazado entre ellos no me funciona bien, pero asi como esta me trae todoas las coincidencias de agencias y me las muestra en un datagrid, pero ahora quiero que me mustre solo las agencias que coincidan con lo que alla seleccionado en cada dropdownlist
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Control Language="VB" AutoEventWireup="true" Codebehind="Agencia.ascx.cs" Inherits="Rainbow.DesktopModules.Agencia.Agencia" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" debug="True"%>
<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()
BindCiudad()
end if
End Sub
Private Sub BindCiudad()
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 CiudadID, Nombre_Ciudad from Ciudad where CiudadID=" & DropDownList1.SelectedItem.Value , MyConnection)
MyCommand.Fill(ds,"Ciudad")
DropDownList2.DataSource = ds.Tables("Ciudad").DefaultView
DropDownList2.DataTextField = "Nombre_Ciudad"
DropDownList2.DataValueField ="CiudadID"
DropDownList2.DataBind()
BindUbicacion()
End Sub
Private Sub BindUbicacion()
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 UbicacionID, Descripcion from Ubicacion WHERE UbicacionID=" & DropDownList2.SelectedItem.Value, MyConnection)
MyCommand.Fill(ds,"Ubicacion")
DropDownList3.DataSource = ds.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
Sub Button1_Click(sender As Object, e As EventArgs)
Dim s As String = "Elementos seleccionados:<br>"
Dim i As Int32
For i = 0 to Check1.Items.Count-1
If not Check1.Items(i).Selected Then
Iblmessage.Text = "Es necesario que seleccione un servicio"
Else If Check1.Items(i).Selected Then
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("select Identificador, Direccion, Telefono, Estado, Ciudad, Ubicacion from Agencia", MyConnection)
ds = new DataSet()
MyCommand.Fill(ds, "Agencia")
MyDataGrid.DataSource=ds.Tables("Agencia").Default View
MyDataGrid.DataBind()
End If
Next
End Sub
</script>
</HEAD>
<body>
<form id="Form1" method="post" encType="text/html" runat="server">
&n bsp; &nbs p;
<TABLE id="Table1" height="366" cellSpacing="0" cellPadding="0" width="490" align="center"
bgColor="aliceblue" border="0">
<TR>
<TD width="549" height="20"></TD>
</TR>
<TR>
Seleccione el estado, la ciudad y/o el servicio que desea localizar:
<TD width="549" height="20"><BR>
<asp:checkboxlist id="Check1" runat="server" repeatcolumns="3">
<asp:ListItem>Agencia</asp:ListItem>
<asp:ListItem>Cajeros automáticos</asp:ListItem>
<asp:ListItem>Agencia con estacionamiento</asp:ListItem>
<asp:ListItem>Autobanco</asp:ListItem>
<asp:ListItem>Taquilla externa</asp:ListItem>
</asp:checkboxlist></TD>
</TR>
<TR>
<TD width="549" height="20"></TD>
</TR>
<TR>
<TD vAlign="top" align="center" width="550" height="186">
<TABLE id="Table2" cellSpacing="0" cellPadding="10" width="100%" bgColor="aliceblue" border="0">
<TR>
<TD width="108" height="29"> &n bsp;Estado:</TD>
<TD width="458" height="29"><asp:dropdownlist id="DropDownList1" runat="server" BackColor="AliceBlue" Font-Names="Arial" ForeColor="Black"
AutoPostBack="True"></asp:dropdownlist></TD>
</TR>
</TABLE>
<TABLE id="Table3" cellSpacing="0" cellPadding="10" width="100%" border="0">
<TR bgColor="aliceblue">
<TD style="WIDTH: 115px" width="115" height="26">
Ciudad:</TD>
<TD width="437" height="26"><asp:dropdownlist id="Dropdownlist2" runat="server" BackColor="AliceBlue" AutoPostBack="True"></asp:dropdownlist></TD>
</TR>
</TABLE>
<TABLE id="Table4" cellSpacing="0" cellPadding="10" width="100%" border="0">
<TR bgColor="aliceblue">
<TD style="WIDTH: 100px" width="100" height="26"> &n bsp;Ubicación:</TD>
<TD width="437" height="26"><asp:dropdownlist id="Dropdownlist3" runat="server" BackColor="AliceBlue" AutoPostBack="True"></asp:dropdownlist></TD>
</TR>
</TABLE>
<P> </P>
<P><asp:button id="Button1" onclick="Button1_Click" runat="server" BackColor="SteelBlue" Text="Buscar"></asp:button><BR>
<asp:label id="Iblmessage" runat="server" font-size="8pt" font-name="Verdana"></asp:label><BR>
</P>
</TD>
</TR>
</TABLE>
</TD></TABLE></TR></TABLE></TD>
<ASP:DataGrid id="MyDataGrid" runat="server" Width="700" BackColor="#ffffff" BorderColor="black"
ShowFooter="false" CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#ffffff"
EnableViewState="false" />
</form>
</body>
</HTML> |