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.ConnectionStrings("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" <gc_0620@yahoo.com> escreveu na mensagem
news:1149688109.345787.19980@f6g2000cwb.googlegroups.com...
[quoted text, click to view] > 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
>