Home All Groups Group Topic Archive Search About
Author
15 Nov 2006 7:47 PM
Milton Snider
I am somewhat new to asp.net.  I have a form which is always in insert mode
and I am trying to let one dropdownlist(dropdownlist1) select a state and
then limit the number of cities populating the 2nd
dropdownlist(dropdownlist2) to only those cities within the state selected
in dropdownlist1.  Dropdownlist1and Dropdownlist2 select their choices from
a table called states_cities and stores the state as the value.  How do I
filter the dropdownlist2 based on the value in dropdownlist1.  Both
dropdownlists are bound to the same table called requests where each stores
a value in state, and city respectively.  Any help would be appreciated.
thanks
Milton

Author
15 Nov 2006 8:03 PM
Yvonne
Hi Milton,
You can handle this in the whith the event handler for
DropDownList1_SelectedIndexChanged. There you may asign the new
selection of cities to to your second combo.
Yvonne

Milton Snider schrieb:

Show quoteHide quote
> I am somewhat new to asp.net.  I have a form which is always in insert mode
> and I am trying to let one dropdownlist(dropdownlist1) select a state and
> then limit the number of cities populating the 2nd
> dropdownlist(dropdownlist2) to only those cities within the state selected
> in dropdownlist1.  Dropdownlist1and Dropdownlist2 select their choices from
> a table called states_cities and stores the state as the value.  How do I
> filter the dropdownlist2 based on the value in dropdownlist1.  Both
> dropdownlists are bound to the same table called requests where each stores
> a value in state, and city respectively.  Any help would be appreciated.
> thanks
> Milton
Author
15 Nov 2006 8:24 PM
Milton Snider
I assume I should databind() in the SelectedIndexChanged event handler code
but how do I tell the DropDownList2 to Databind() ? If I try to use
Me.Dropdownlist2 it is not under the me object.  how do I tell it to
Databind.  it gets its listing from a datasource.

thanks
Milton
Show quoteHide quote
"Yvonne" <letter***@privatezone.ch> wrote in message
news:1163621028.429101.290480@h48g2000cwc.googlegroups.com...
> Hi Milton,
> You can handle this in the whith the event handler for
> DropDownList1_SelectedIndexChanged. There you may asign the new
> selection of cities to to your second combo.
> Yvonne
>
> Milton Snider schrieb:
>
>> I am somewhat new to asp.net.  I have a form which is always in insert
>> mode
>> and I am trying to let one dropdownlist(dropdownlist1) select a state and
>> then limit the number of cities populating the 2nd
>> dropdownlist(dropdownlist2) to only those cities within the state
>> selected
>> in dropdownlist1.  Dropdownlist1and Dropdownlist2 select their choices
>> from
>> a table called states_cities and stores the state as the value.  How do I
>> filter the dropdownlist2 based on the value in dropdownlist1.  Both
>> dropdownlists are bound to the same table called requests where each
>> stores
>> a value in state, and city respectively.  Any help would be appreciated.
>> thanks
>> Milton
>
Author
15 Nov 2006 8:28 PM
Yvonne
can you post your sourcecode, please?

Milton Snider schrieb:

Show quoteHide quote
> I assume I should databind() in the SelectedIndexChanged event handler code
> but how do I tell the DropDownList2 to Databind() ? If I try to use
> Me.Dropdownlist2 it is not under the me object.  how do I tell it to
> Databind.  it gets its listing from a datasource.
>
> thanks
> Milton
> "Yvonne" <letter***@privatezone.ch> wrote in message
> news:1163621028.429101.290480@h48g2000cwc.googlegroups.com...
> > Hi Milton,
> > You can handle this in the whith the event handler for
> > DropDownList1_SelectedIndexChanged. There you may asign the new
> > selection of cities to to your second combo.
> > Yvonne
> >
> > Milton Snider schrieb:
> >
> >> I am somewhat new to asp.net.  I have a form which is always in insert
> >> mode
> >> and I am trying to let one dropdownlist(dropdownlist1) select a state and
> >> then limit the number of cities populating the 2nd
> >> dropdownlist(dropdownlist2) to only those cities within the state
> >> selected
> >> in dropdownlist1.  Dropdownlist1and Dropdownlist2 select their choices
> >> from
> >> a table called states_cities and stores the state as the value.  How do I
> >> filter the dropdownlist2 based on the value in dropdownlist1.  Both
> >> dropdownlists are bound to the same table called requests where each
> >> stores
> >> a value in state, and city respectively.  Any help would be appreciated.
> >> thanks
> >> Milton
> >
Author
15 Nov 2006 8:57 PM
Milton Snider
Here is the formpage.  There is no code on the VB page yet.
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="cascadingDropDownLists.aspx.vb"
Inherits="Test_cascadingDropDownLists" %>

<!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>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<asp:SqlDataSource ID="FormDataSource" runat="server" ConnectionString="<%$
ConnectionStrings:Req2ExceedConnectionString6 %>"

DeleteCommand="DELETE FROM [District_Cities] WHERE [tableID] = @tableID"
InsertCommand="INSERT INTO [District_Cities] ([Dist], [City]) VALUES (@Dist,
@City)"

SelectCommand="SELECT [tableID], [Dist], [City] FROM [District_Cities]"
UpdateCommand="UPDATE [District_Cities] SET [Dist] = @Dist, [City] = @City
WHERE [tableID] = @tableID">

<DeleteParameters>

<asp:Parameter Name="tableID" Type="Int32" />

</DeleteParameters>

<UpdateParameters>

<asp:Parameter Name="Dist" Type="String" />

<asp:Parameter Name="City" Type="String" />

<asp:Parameter Name="tableID" Type="Int32" />

</UpdateParameters>

<InsertParameters>

<asp:Parameter Name="Dist" Type="String" />

<asp:Parameter Name="City" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

<asp:FormView ID="FormView1" runat="server" AllowPaging="True"
DataKeyNames="tableID"

DataSourceID="FormDataSource" DefaultMode="Insert" Height="160px"
Width="408px">

<EditItemTemplate>

tableID:

<asp:Label ID="tableIDLabel1" runat="server" Text='<%# Eval("tableID")
%>'></asp:Label><br />

Dist:

<asp:TextBox ID="DistTextBox" runat="server" Text='<%# Bind("Dist") %>'>

</asp:TextBox><br />

City:

<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>'>

</asp:TextBox><br />

<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update"

Text="Update">

</asp:LinkButton>

<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"

Text="Cancel">

</asp:LinkButton>

</EditItemTemplate>

<InsertItemTemplate>

Dist:

<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="DDL_District" DataTextField="DISTRICT"

DataValueField="DIST"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"

SelectedValue='<%# Bind("Dist") %>'>

</asp:DropDownList><asp:SqlDataSource ID="DDL_District" runat="server"
ConnectionString="<%$ ConnectionStrings:Req2ExceedConnectionString6 %>"

SelectCommand="SELECT DISTINCT [DISTRICT], [DIST] FROM
[Cities]"></asp:SqlDataSource>

<br />

City:

<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="DDL_City"
DataTextField="DUTY_STAT"

DataValueField="DUTY_STAT" SelectedValue='<%# Bind("City") %>'>

</asp:DropDownList><asp:SqlDataSource ID="DDL_City" runat="server"
ConnectionString="<%$ ConnectionStrings:Req2ExceedConnectionString6 %>"

SelectCommand="SELECT [DUTY_STAT], [ID] FROM [Cities] WHERE ([DIST] =
@DIST)">

<SelectParameters>

<asp:ControlParameter ControlID="DropDownList1" Name="DIST"
PropertyName="SelectedValue"

Type="String" />

</SelectParameters>

</asp:SqlDataSource>

<br />

<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert"

Text="Insert"></asp:LinkButton>

<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"

Text="Cancel"></asp:LinkButton>

</InsertItemTemplate>

<ItemTemplate>

tableID:

<asp:Label ID="tableIDLabel" runat="server" Text='<%# Eval("tableID")
%>'></asp:Label><br />

Dist:

<asp:Label ID="DistLabel" runat="server" Text='<%# Bind("Dist")
%>'></asp:Label><br />

City:

<asp:Label ID="CityLabel" runat="server" Text='<%# Bind("City")
%>'></asp:Label><br />

<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit"

Text="Edit"></asp:LinkButton>

<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
CommandName="Delete"

Text="Delete"></asp:LinkButton>

<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New"

Text="New"></asp:LinkButton>

</ItemTemplate>

</asp:FormView>

</form>

</body>

</html>
Author
15 Nov 2006 9:11 PM
Yvonne
Hy Milton,

You're right and you should have access to your second combo...

I'm not very use to VB-Code, but what you have to change is: remove the
select-statement for the second combo from the aspx-file and do it in
DropDownList1_SelectedIndexChanged.

yvonne


Show quoteHide quote
On 15 Nov., 21:57, "Milton Snider" <miltonsni***@yahoo.com> wrote:
> Here is the formpage.  There is no code on the VB page yet.
> <%@ Page Language="VB" AutoEventWireup="false"
> CodeFile="cascadingDropDownLists.aspx.vb"
> Inherits="Test_cascadingDropDownLists" %>
>
> ...
Author
15 Nov 2006 9:26 PM
Milton Snider
Yes, I understand.  I have don't know how to assign a datasource, select
statement with code for a combobox.


Show quoteHide quote
"Yvonne" <letter***@privatezone.ch> wrote in message
news:1163625100.696376.233890@f16g2000cwb.googlegroups.com...
> Hy Milton,
>
> You're right and you should have access to your second combo...
>
> I'm not very use to VB-Code, but what you have to change is: remove the
> select-statement for the second combo from the aspx-file and do it in
> DropDownList1_SelectedIndexChanged.
>
> yvonne
>
>
> On 15 Nov., 21:57, "Milton Snider" <miltonsni***@yahoo.com> wrote:
>> Here is the formpage.  There is no code on the VB page yet.
>> <%@ Page Language="VB" AutoEventWireup="false"
>> CodeFile="cascadingDropDownLists.aspx.vb"
>> Inherits="Test_cascadingDropDownLists" %>
>>
>> ...
>
Author
16 Nov 2006 3:16 AM
MikeS
Maybe set  AutoPostBack="True" on DropDownList1. Then the
ControlParameter you set up should kick in and the databinding will
happen as expected.

Note that without that, not even DropDownList1_SelectedIndexChanged
will fire. Not that you need it, since you have the control parameter.

Also note that when controls are part of a data control,  if you want
at it, you have to do a FindControl.

So say you didn't use an asp:ControlParameter but just a regular
asp:Parameter in the DropDownList2 data source, then you can handle the
binding in DropDownList1_SelectedIndexChanged like so:


        Dim dl1 As DropDownList =
FormView1.FindControl("DropDownList1")
        Dim dl2 As DropDownList =
FormView1.FindControl("DropDownList2")
        Dim ods As ObjectDataSource = FormView1.FindControl("DDL_City")
        ods.SelectParameters("DIST").DefaultValue = dl1.SelectedValue
        dl2.DataBind()