473,599 Members | 3,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New to ASP.Net, Cascading DropDown List in Detail View...Please help

Sam
A) Destination Table with 4 Fields.

1) Last Name
2) First Name
3) State
4) Zip Code.
B) Look up table State/Zip Code with 2 Fields

1) State
2) Zip Code.

I created a DetailView Form in Asp.net to Insert/Update Destination
Table. Destination Table's State and Zip Code Fields are converted from
Bound Column to Item/Edit/Insert Template, Created 2 Drop Down Lists,
DDLState and DDLZIP. I am using '<%# Bind(...)%>' for both of them.
Also, I do have 2 SQLDatasource for DDL's (i.e. SqlState for DDLState
and SqlZip for DDLZIP).

My Intention is very simple:

When user select State Name from DDLState DropDownList List (example:
NJ), in DDLZIP Dropdown list it must show only Zip Codes from that
State. In order to Change the Value of DDLZIP, users must Change the
Value of DDLState. Basically DDLZIP is Child/Dependant of DDLState. I
did correctly setup proper reference to DDLState in SelectedParamet ers,
Control Parameters, PropertyName in SqlZip (SqlDataSource for DDLZIP).

This Cascading dropdown logic does work Fine in a Form without a
DetailView. I tested it. But I am having hard time to implement this
within Detail View.
Any Complete Example (i.e. Form with Subs) will be highly appreciated.
I will be glad if this example is based on NorthWind Database.

Thanks a lot for your time and efforts.

- Sam

Jun 7 '06 #1
2 9726
well,

the first Bind to the 2nd DDL will be returning just the ZIP Code that
actually is in the database unless you choose otherwise.

my opinion on the matter is:

1 DDL have a function on OnSelectedIndex Changed that goes to the DB and gett
all the zip codes for that State and Populate the 2nd DDL, that's simple.

like:

myFisrtDDL_Sele ctedIndexChange d( ... )
mySecondDDL.Dat aSource = populateSecondD D( myFirstDDL.Sele ctedValue )
mySecondDDLData Bind()

Function populateSecondD D( state as String ) as ArrayList

' make the connection to the Database
Dim aArray as new ArrayList
Dim dReader As SqlDataReader
Dim Connection As SqlConnection
Connection = New _
SqlConnection(C onfigurationMan ager.Connection Strings("ConnSt ring").Connecti onString)
Dim command As SqlCommand
command = New SqlCommand()
command.Connect ion = Connection
command.Command Type = Data.CommandTyp e.Text
command.Command Text = "SELECT zipCodes FROM table WHERE State = @state"
Connection.Para meters.AddWithV alue("@state", state)
Connection.Open ()
myDataReader = Connection.Exec ute.Reader()

If myDataReader.Ha sRows Then
While myDataReader.Re ad()
aArray.Add( myDataReader.it em("zipCodes") )
End While
End If
myDataReader.Cl ose()
Connection.Clos e()
Return aArray
End Function
and of course, on the GridView_RowCre ated statment you just do the same

GridView_RowCre ated(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewRowEventArg s)
If e.Row.RowType = DataControlRowT ype.DataRow Then
If e.Row.RowState = DataControlRowS tate.Edit
CType(e.Row.Fin dControl("mySec ondDDL"), DropDownList).D ataSource =
populateSecondD DL( _
CType(e.Row.Fin dControl("myFir stDDL"),
DropDownList).S electedValue
CType(e.Row.Fin dControl("mySec ondDDL"), DropDownList).D ataBind()
End If
End if
--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"Sam" <gc*****@yahoo. com> escreveu na mensagem
news:11******** *************@f 6g2000cwb.googl egroups.com...
A) Destination Table with 4 Fields.

1) Last Name
2) First Name
3) State
4) Zip Code.
B) Look up table State/Zip Code with 2 Fields

1) State
2) Zip Code.

I created a DetailView Form in Asp.net to Insert/Update Destination
Table. Destination Table's State and Zip Code Fields are converted from
Bound Column to Item/Edit/Insert Template, Created 2 Drop Down Lists,
DDLState and DDLZIP. I am using '<%# Bind(...)%>' for both of them.
Also, I do have 2 SQLDatasource for DDL's (i.e. SqlState for DDLState
and SqlZip for DDLZIP).

My Intention is very simple:

When user select State Name from DDLState DropDownList List (example:
NJ), in DDLZIP Dropdown list it must show only Zip Codes from that
State. In order to Change the Value of DDLZIP, users must Change the
Value of DDLState. Basically DDLZIP is Child/Dependant of DDLState. I
did correctly setup proper reference to DDLState in SelectedParamet ers,
Control Parameters, PropertyName in SqlZip (SqlDataSource for DDLZIP).

This Cascading dropdown logic does work Fine in a Form without a
DetailView. I tested it. But I am having hard time to implement this
within Detail View.
Any Complete Example (i.e. Form with Subs) will be highly appreciated.
I will be glad if this example is based on NorthWind Database.

Thanks a lot for your time and efforts.

- Sam

Jun 7 '06 #2
Sam
Thank you Bruno for your help. It works.

Regards

- Sam
Bruno Alexandre wrote:
well,

the first Bind to the 2nd DDL will be returning just the ZIP Code that
actually is in the database unless you choose otherwise.

my opinion on the matter is:

1 DDL have a function on OnSelectedIndex Changed that goes to the DB and gett
all the zip codes for that State and Populate the 2nd DDL, that's simple.

like:

myFisrtDDL_Sele ctedIndexChange d( ... )
mySecondDDL.Dat aSource = populateSecondD D( myFirstDDL.Sele ctedValue )
mySecondDDLData Bind()

Function populateSecondD D( state as String ) as ArrayList

' make the connection to the Database
Dim aArray as new ArrayList
Dim dReader As SqlDataReader
Dim Connection As SqlConnection
Connection = New _
SqlConnection(C onfigurationMan ager.Connection Strings("ConnSt ring").Connecti onString)
Dim command As SqlCommand
command = New SqlCommand()
command.Connect ion = Connection
command.Command Type = Data.CommandTyp e.Text
command.Command Text = "SELECT zipCodes FROM table WHERE State = @state"
Connection.Para meters.AddWithV alue("@state", state)
Connection.Open ()
myDataReader = Connection.Exec ute.Reader()

If myDataReader.Ha sRows Then
While myDataReader.Re ad()
aArray.Add( myDataReader.it em("zipCodes") )
End While
End If
myDataReader.Cl ose()
Connection.Clos e()
Return aArray
End Function
and of course, on the GridView_RowCre ated statment you just do the same

GridView_RowCre ated(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Grid ViewRowEventArg s)
If e.Row.RowType = DataControlRowT ype.DataRow Then
If e.Row.RowState = DataControlRowS tate.Edit
CType(e.Row.Fin dControl("mySec ondDDL"), DropDownList).D ataSource =
populateSecondD DL( _
CType(e.Row.Fin dControl("myFir stDDL"),
DropDownList).S electedValue
CType(e.Row.Fin dControl("mySec ondDDL"), DropDownList).D ataBind()
End If
End if
--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"Sam" <gc*****@yahoo. com> escreveu na mensagem
news:11******** *************@f 6g2000cwb.googl egroups.com...
A) Destination Table with 4 Fields.

1) Last Name
2) First Name
3) State
4) Zip Code.
B) Look up table State/Zip Code with 2 Fields

1) State
2) Zip Code.

I created a DetailView Form in Asp.net to Insert/Update Destination
Table. Destination Table's State and Zip Code Fields are converted from
Bound Column to Item/Edit/Insert Template, Created 2 Drop Down Lists,
DDLState and DDLZIP. I am using '<%# Bind(...)%>' for both of them.
Also, I do have 2 SQLDatasource for DDL's (i.e. SqlState for DDLState
and SqlZip for DDLZIP).

My Intention is very simple:

When user select State Name from DDLState DropDownList List (example:
NJ), in DDLZIP Dropdown list it must show only Zip Codes from that
State. In order to Change the Value of DDLZIP, users must Change the
Value of DDLState. Basically DDLZIP is Child/Dependant of DDLState. I
did correctly setup proper reference to DDLState in SelectedParamet ers,
Control Parameters, PropertyName in SqlZip (SqlDataSource for DDLZIP).

This Cascading dropdown logic does work Fine in a Form without a
DetailView. I tested it. But I am having hard time to implement this
within Detail View.
Any Complete Example (i.e. Form with Subs) will be highly appreciated.
I will be glad if this example is based on NorthWind Database.

Thanks a lot for your time and efforts.

- Sam


Jun 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4301
by: Ian | last post by:
Can anyone help me with a problem I have. What I need to be able to do is have the user presented with a single dropdown menu within a form using HTML <SELECT> and <OPTION>. Once they choose a particular option I then want another dropdown to appear alongside it with a list of options that are dependent on what was selected in the first dropdown. Then I want the same thing to happen a third time, i.e when the user selects an option from...
9
6750
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the second combo to change depending on what values the user selects in the first box, it's just that every time the user changes the first combobox, the second combobox FOR EVERY RECORD goes blank.
0
1304
by: pintu | last post by:
Hello everybody...Any one plz help in solving my problem mentioned below.. I am creating an application in asp.net 2.0.I want 2 dropdowns i.e customer and branch to be present inside detailsview control..which fetches data from database..On selection of customer dd branch should be filled..In insert mode of details view i want this so that i can insert other fields present in the details view and click insert button to insert the...
4
64569
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one determines the available options in the other. TERMINOLOGY Row Source: The table/query from which the Combo Box or List Box gets its values. Note: There are other types of row sources that can be used but for simplicity we will stick with Tables...
19
2317
by: Amanduh | last post by:
Hi again, brilliant developers. I'm having serious issues with cascading comboboxes. I had it working perfectly before, but then was asked to add an additional variable and everything went haywire (surely due to my incompetence). I've printed out Rabbit's tutorial and read it many times, but like others, I feel I need a more elementary approach. Please let me explain: I'm creating a database for entering information for research studies. ...
8
2927
by: Wingot | last post by:
Hey, I have a program I am trying to write using Visual C#, SQL Server 2005/2008, and Visual Studio 2008, and one part of it includes a Schema called Client. Inside this schema, three tables exist named Country, MedicalCondition, and Customer.
3
1953
kcdoell
by: kcdoell | last post by:
Hello: I have been struggling with building a cascading list on a form that I created. My problem is that I am getting a "Datatype Mismatch in criteria expression" error that I can not seem to figure out. I hope someone can help... The background is that I have two drop down boxes on a form called: cboPolicyName cboPolicyNumber On the rowsource for the cboPolicyName I have it pointing to my table:
3
3975
kcdoell
by: kcdoell | last post by:
I have 5 cascading combo boxes on a form. Below is a sample of my vb in the first combo box: Private Sub CboDivision_AfterUpdate() 'When the Division is selected, the appropriate Segment list will 'display in the drop down list of CboSegment With Me! If IsNull(Me!cboDivision) Then
5
10331
by: =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post by:
I have a VS 2008 ASP.NET webform that has a reportview tag on it, accessing an .RLDC report in local report. The columns for the report are essentially: Month Item #1 Item#2 Item#3 I would like to add a checkbox or dropdown control to the .RLDC and have Item #1, Item #2, or Item #3 display conditionally based on a checkbox being clicked or a dropdown value being selected.
0
8401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8053
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8268
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6729
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.