.NET DROP DOWN LIST PROBLEM 
Author Message
 .NET DROP DOWN LIST PROBLEM

I have 4 dynamic drop down lists(Region, Country, State, City) the
Country depends on the region selected, the State depends on the
Country and the City depends on the States,all this information is in
SQL server, thed I add and item (DropDownList1.Items.Insert(0, "select
an item")to each dropdownlist so far this is working fine.  The
problem that I have is that I need the country, state, and city
dropdownlists to be reset to the first list item the one that I insert
when the region changes, and also I need to add a value 0 to this
item.

I am new to VB.NET maybe this is not the best approch, but with my
knowledge, that is what I can do.

I will appreciate any help, Thanks.
This is the code :



Namespace="Microsoft.Saturn.Framework.Web.UI"
Assembly="Microsoft.Saturn.Framework, Version=0.5.464.0,
Culture=neutral, PublicKeyToken=6f763c9966660626" %>
<script runat="server">

    ' Insert page code here
    '

        Sub Page_Load(Sender As Object, E As EventArgs)
            If Not Page.IsPostBack Then
                DropDownList1.DataValueField = "id"
                DropDownList1.DataTextField = "region_name"
                DropDownList1.DataSource = Getregion()
                DropDownList1.DataBind()
                DropDownList1.Items.Insert(0, "select an item")

           End If

        End Sub

        Function Getregion() As System.Data.DataSet

            Dim connectionString As String = "server='localhost';
trusted_connection=true; Database='comida'"
            Dim sqlConnection As System.Data.SqlClient.SqlConnection =
New System.Data.SqlClient.SqlConnection(connectionString)

            Dim queryString As String = "SELECT
[regiones].[ID],[regiones].[region_name] FROM [regiones] order by
region_name"
            Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

            Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter =
New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
            Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
            dataAdapter.Fill(dataSet)

            Return dataSet
        End Function

        Function Getpais() As System.Data.DataSet

            Dim connectionString As String = "server='localhost';
trusted_connection=true; Database='comida'"
            Dim sqlConnection As System.Data.SqlClient.SqlConnection =
New System.Data.SqlClient.SqlConnection(connectionString)

            Dim queryString As String = "SELECT
[paises].[ID],[paises].[description] FROM [paises] where
([paises].[region] = " & DropDownList1.selectedItem.Value &")" &
"order by description"
            Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

            Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter =
New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
            Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
            dataAdapter.Fill(dataSet)

            Return dataSet
        End Function

        Function Getestado() As System.Data.DataSet

            Dim connectionString As String = "server='localhost';
trusted_connection=true; Database='comida'"
            Dim sqlConnection As System.Data.SqlClient.SqlConnection =
New System.Data.SqlClient.SqlConnection(connectionString)

            Dim queryString As String = "SELECT
[estados].[ID],[estados].[estado] FROM [estados] where
([estados].[pais] = " & DropDownList2.selectedItem.Value &")" & "order
by estado"
            Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

            Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter =
New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
            Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
            dataAdapter.Fill(dataSet)

            Return dataSet
        End Function

        Function Getciudad() As System.Data.DataSet

            Dim connectionString As String = "server='localhost';
trusted_connection=true; Database='comida'"
            Dim sqlConnection As System.Data.SqlClient.SqlConnection =
New System.Data.SqlClient.SqlConnection(connectionString)

            Dim queryString As String = "SELECT
[ciudades].[ID],[ciudades].[ciudad] FROM [ciudades] where
([ciudades].[estado] = " & DropDownList3.selectedItem.Value &")" &
"order by ciudad"
            Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

            Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter =
New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
            Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
            dataAdapter.Fill(dataSet)

            Return dataSet
        End Function

        Sub DropDownList1_SelectedIndexChanged(sender As Object, e As
EventArgs)
                DropDownList2.DataValueField = "id"
                DropDownList2.DataTextField = "description"
                DropDownList2.DataSource = Getpais()
                DropDownList2.DataBind()
                DropDownList2.Items.Insert(0, "select an item")
        End Sub

        Sub DropDownList2_SelectedIndexChanged(sender As Object, e As
EventArgs)
                DropDownList3.DataValueField = "id"
                DropDownList3.DataTextField = "estado"
                DropDownList3.DataSource = Getestado()
                DropDownList3.DataBind()
                DropDownList3.Items.Insert(0, "select an item")

        End Sub

        Sub DropDownList3_SelectedIndexChanged(sender As Object, e As
EventArgs)
                DropDownList4.DataValueField = "id"
                DropDownList4.DataTextField = "ciudad"
                DropDownList4.DataSource = Getciudad()
                DropDownList4.DataBind()
                DropDownList4.Items.Insert(0, "select an item")
        End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:DropDownList id="DropDownList1" runat="server"
Height="30px" Width="150px" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
        <br />
        <br />
        <asp:DropDownList id="DropDownList2" runat="server"
Height="30px" Width="150px" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"></asp:DropDownList>
        <br />
        <br />
        <asp:DropDownList id="DropDownList3" runat="server"
Height="30px" Width="150px" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged"></asp:DropDownList>
        <br />
        <br />
        <asp:DropDownList id="DropDownList4" runat="server"
Height="30px" Width="150px" AutoPostBack="True"></asp:DropDownList>
    </form>
</body>
</html>



Wed, 13 Apr 2005 22:28:40 GMT  
 .NET DROP DOWN LIST PROBLEM
You can reset the listbox to the first item:

listbox.SelectedIndex=0

Gabor


Quote:
> I have 4 dynamic drop down lists(Region, Country, State, City) the
> Country depends on the region selected, the State depends on the
> Country and the City depends on the States,all this information is in
> SQL server, thed I add and item (DropDownList1.Items.Insert(0, "select
> an item")to each dropdownlist so far this is working fine.  The
> problem that I have is that I need the country, state, and city
> dropdownlists to be reset to the first list item the one that I insert
> when the region changes, and also I need to add a value 0 to this
> item.

> I am new to VB.NET maybe this is not the best approch, but with my
> knowledge, that is what I can do.

> I will appreciate any help, Thanks.
> This is the code :



> Namespace="Microsoft.Saturn.Framework.Web.UI"
> Assembly="Microsoft.Saturn.Framework, Version=0.5.464.0,
> Culture=neutral, PublicKeyToken=6f763c9966660626" %>
> <script runat="server">

>     ' Insert page code here
>     '

>         Sub Page_Load(Sender As Object, E As EventArgs)
>             If Not Page.IsPostBack Then
>                 DropDownList1.DataValueField = "id"
>                 DropDownList1.DataTextField = "region_name"
>                 DropDownList1.DataSource = Getregion()
>                 DropDownList1.DataBind()
>                 DropDownList1.Items.Insert(0, "select an item")

>            End If

>         End Sub

>         Function Getregion() As System.Data.DataSet

>             Dim connectionString As String = "server='localhost';
> trusted_connection=true; Database='comida'"
>             Dim sqlConnection As System.Data.SqlClient.SqlConnection =
> New System.Data.SqlClient.SqlConnection(connectionString)

>             Dim queryString As String = "SELECT
> [regiones].[ID],[regiones].[region_name] FROM [regiones] order by
> region_name"
>             Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
> System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

>             Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter =
> New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
>             Dim dataSet As System.Data.DataSet = New
> System.Data.DataSet
>             dataAdapter.Fill(dataSet)

>             Return dataSet
>         End Function

>         Function Getpais() As System.Data.DataSet

>             Dim connectionString As String = "server='localhost';
> trusted_connection=true; Database='comida'"
>             Dim sqlConnection As System.Data.SqlClient.SqlConnection =
> New System.Data.SqlClient.SqlConnection(connectionString)

>             Dim queryString As String = "SELECT
> [paises].[ID],[paises].[description] FROM [paises] where
> ([paises].[region] = " & DropDownList1.selectedItem.Value &")" &
> "order by description"
>             Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
> System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

>             Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter =
> New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
>             Dim dataSet As System.Data.DataSet = New
> System.Data.DataSet
>             dataAdapter.Fill(dataSet)

>             Return dataSet
>         End Function

>         Function Getestado() As System.Data.DataSet

>             Dim connectionString As String = "server='localhost';
> trusted_connection=true; Database='comida'"
>             Dim sqlConnection As System.Data.SqlClient.SqlConnection =
> New System.Data.SqlClient.SqlConnection(connectionString)

>             Dim queryString As String = "SELECT
> [estados].[ID],[estados].[estado] FROM [estados] where
> ([estados].[pais] = " & DropDownList2.selectedItem.Value &")" & "order
> by estado"
>             Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
> System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

>             Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter =
> New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
>             Dim dataSet As System.Data.DataSet = New
> System.Data.DataSet
>             dataAdapter.Fill(dataSet)

>             Return dataSet
>         End Function

>         Function Getciudad() As System.Data.DataSet

>             Dim connectionString As String = "server='localhost';
> trusted_connection=true; Database='comida'"
>             Dim sqlConnection As System.Data.SqlClient.SqlConnection =
> New System.Data.SqlClient.SqlConnection(connectionString)

>             Dim queryString As String = "SELECT
> [ciudades].[ID],[ciudades].[ciudad] FROM [ciudades] where
> ([ciudades].[estado] = " & DropDownList3.selectedItem.Value &")" &
> "order by ciudad"
>             Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
> System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

>             Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter =
> New System.Data.SqlClient.SqlDataAdapter(sqlCommand)
>             Dim dataSet As System.Data.DataSet = New
> System.Data.DataSet
>             dataAdapter.Fill(dataSet)

>             Return dataSet
>         End Function

>         Sub DropDownList1_SelectedIndexChanged(sender As Object, e As
> EventArgs)
>                 DropDownList2.DataValueField = "id"
>                 DropDownList2.DataTextField = "description"
>                 DropDownList2.DataSource = Getpais()
>                 DropDownList2.DataBind()
>                 DropDownList2.Items.Insert(0, "select an item")
>         End Sub

>         Sub DropDownList2_SelectedIndexChanged(sender As Object, e As
> EventArgs)
>                 DropDownList3.DataValueField = "id"
>                 DropDownList3.DataTextField = "estado"
>                 DropDownList3.DataSource = Getestado()
>                 DropDownList3.DataBind()
>                 DropDownList3.Items.Insert(0, "select an item")

>         End Sub

>         Sub DropDownList3_SelectedIndexChanged(sender As Object, e As
> EventArgs)
>                 DropDownList4.DataValueField = "id"
>                 DropDownList4.DataTextField = "ciudad"
>                 DropDownList4.DataSource = Getciudad()
>                 DropDownList4.DataBind()
>                 DropDownList4.Items.Insert(0, "select an item")
>         End Sub

> </script>
> <html>
> <head>
> </head>
> <body>
>     <form runat="server">
>         <asp:DropDownList id="DropDownList1" runat="server"
> Height="30px" Width="150px" AutoPostBack="True"

OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownLi
st>
Quote:
>         <br />
>         <br />
>         <asp:DropDownList id="DropDownList2" runat="server"
> Height="30px" Width="150px" AutoPostBack="True"

OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"></asp:DropDownLi
st>
Quote:
>         <br />
>         <br />
>         <asp:DropDownList id="DropDownList3" runat="server"
> Height="30px" Width="150px" AutoPostBack="True"

OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged"></asp:DropDownLi
st>

- Show quoted text -

Quote:
>         <br />
>         <br />
>         <asp:DropDownList id="DropDownList4" runat="server"
> Height="30px" Width="150px" AutoPostBack="True"></asp:DropDownList>
>     </form>
> </body>
> </html>



Fri, 15 Apr 2005 08:34:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Drop Down List Box - Drop Down portion does not always disappear after Click event

2. Problems with Combo Drop Down Lists

3. Problem with Combo Drop Down Lists

4. Drop-down list in a list view

5. List of servers in VB for a drop down list

6. Press F1 key while drop-down menu item highlighted, drop-down menu stays on top

7. Data bound drops downs dont drop down!

8. VBA code to go to a bookmarked drop down goes to wrong drop down

9. Max 65536 rows in drop-down list (Access)

10. Getting a drop down resource list when filtering by resource and date range

11. Disable IE5.5 drop down list when I type text within a web page - PLEASE HELP

 

 
Powered by phpBB® Forum Software