Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > New to ASP.Net, Cascading DropDown List in Detail View...Please help

Reply
Thread Tools

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

 
 
Sam
Guest
Posts: n/a
 
      06-07-2006
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 SelectedParameters,
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

 
Reply With Quote
 
 
 
 
Bruno Alexandre
Guest
Posts: n/a
 
      06-07-2006
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 OnSelectedIndexChanged that goes to the DB and gett
all the zip codes for that State and Populate the 2nd DDL, that's simple.

like:

myFisrtDDL_SelectedIndexChanged( ... )
mySecondDDL.DataSource = populateSecondDD( myFirstDDL.SelectedValue )
mySecondDDLDataBind()

Function populateSecondDD( 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(ConfigurationManager.ConnectionStrin gs("ConnString").ConnectionString)
Dim command As SqlCommand
command = New SqlCommand()
command.Connection = Connection
command.CommandType = Data.CommandType.Text
command.CommandText = "SELECT zipCodes FROM table WHERE State = @state"
Connection.Parameters.AddWithValue("@state", state)
Connection.Open()
myDataReader = Connection.Execute.Reader()

If myDataReader.HasRows Then
While myDataReader.Read()
aArray.Add( myDataReader.item("zipCodes"))
End While
End If
myDataReader.Close()
Connection.Close()
Return aArray
End Function


and of course, on the GridView_RowCreated statment you just do the same

GridView_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowState = DataControlRowState.Edit
CType(e.Row.FindControl("mySecondDDL"), DropDownList).DataSource =
populateSecondDDL( _
CType(e.Row.FindControl("myFirstDDL"),
DropDownList).SelectedValue
CType(e.Row.FindControl("mySecondDDL"), DropDownList).DataBind()
End If
End if


--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)


"Sam" <(E-Mail Removed)> escreveu na mensagem
news:(E-Mail Removed) ps.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 SelectedParameters,
> 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
>



 
Reply With Quote
 
 
 
 
Sam
Guest
Posts: n/a
 
      06-09-2006
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 OnSelectedIndexChanged that goes to the DB and gett
> all the zip codes for that State and Populate the 2nd DDL, that's simple.
>
> like:
>
> myFisrtDDL_SelectedIndexChanged( ... )
> mySecondDDL.DataSource = populateSecondDD( myFirstDDL.SelectedValue )
> mySecondDDLDataBind()
>
> Function populateSecondDD( 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(ConfigurationManager.ConnectionStrin gs("ConnString").ConnectionString)
> Dim command As SqlCommand
> command = New SqlCommand()
> command.Connection = Connection
> command.CommandType = Data.CommandType.Text
> command.CommandText = "SELECT zipCodes FROM table WHERE State = @state"
> Connection.Parameters.AddWithValue("@state", state)
> Connection.Open()
> myDataReader = Connection.Execute.Reader()
>
> If myDataReader.HasRows Then
> While myDataReader.Read()
> aArray.Add( myDataReader.item("zipCodes"))
> End While
> End If
> myDataReader.Close()
> Connection.Close()
> Return aArray
> End Function
>
>
> and of course, on the GridView_RowCreated statment you just do the same
>
> GridView_RowCreated(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.GridViewRowEventArgs)
> If e.Row.RowType = DataControlRowType.DataRow Then
> If e.Row.RowState = DataControlRowState.Edit
> CType(e.Row.FindControl("mySecondDDL"), DropDownList).DataSource =
> populateSecondDDL( _
> CType(e.Row.FindControl("myFirstDDL"),
> DropDownList).SelectedValue
> CType(e.Row.FindControl("mySecondDDL"), DropDownList).DataBind()
> End If
> End if
>
>
> --
>
> Bruno Alexandre
> (a Portuguese in Københanv, Danmark)
>
>
> "Sam" <(E-Mail Removed)> escreveu na mensagem
> news:(E-Mail Removed) ps.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 SelectedParameters,
> > 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
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help about Cascading DropDown naag c ASP .Net 1 10-16-2009 01:53 PM
Ajax Cascading Dropdown List Raymond Chiu ASP .Net Web Controls 0 04-08-2008 02:41 AM
ajax cascading dropdown: second dropdown disabled acadam ASP .Net 0 12-27-2006 10:59 AM
New to ASP.Net, Cascading DropDown List in Detail View...Please help Sam ASP .Net 2 06-09-2006 12:10 AM
forms: master/detail dropdown list? Jerome ASP .Net 4 08-17-2005 02:11 PM



Advertisments