Skip Navigation

Home > Support > Developers > AS Web Forms > Design Patterns > Limit a dropdown on the Web Forms based on a value in another dropdown.

Limit a dropdown on the Web Forms based on a value in another dropdown.

Sometimes, you may have a set of drop downs on a single AS Web Form that rely on one another. For an example, consider State and County.

The following pattern may be used on the page hosting the ASWebForms ASDataEditor control:

In your code behind, add an object to server as a reference to your data editor:

Protected WithEvents ctlASDataEditor As ASWebForms.AlgonquinStudios.Controls.ASDataEditor

Then, set a reference to this in the Page_Load event:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ctlASDataEditor = Me.FindControl("ctlASDataEditor")
End Sub

Finally, add code to the ctlASDataEditor_PreRender event which will perform the appropriate look-up changes and reset the drop down:

Private Sub ctlASDataEditor_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles ctlASDataEditor.PreRender
Dim cboState As System.Web.UI.HtmlControls.HtmlSelect
Dim htParameters As Hashtable
Dim intStateIdent As Int32
Dim dsResults As System.Data.DataSet
Dim dv As System.Data.DataView
Dim intCountyIdent As Int32
cboState = Helper.GetControl(ctlASDataEditor, "StateIdent")
cboState.Attributes.Add("onchange", "forms[0].submit();")
intStateIdent = CType(Helper.GetControl(ctlASDataEditor.pnlDataControls, ("State")), System.Web.UI.HtmlControls.HtmlSelect).Value
intCountyIdent = CType(Helper.GetControl(ctlASDataEditor.pnlDataControls, ("CountyIdent")), System.Web.UI.HtmlControls.HtmlSelect).Value
With CType(Helper.GetControl(ctlASDataEditor.pnlDataControls, ("CountyIdent")), System.Web.UI.HtmlControls.HtmlSelect)
htParameters = New Hashtable
htParameters.Add("@intStateIdent", intStateIdent)
If Me.Helper.CallStoredProcedure("uspGetActiveCountyByStateIdent", htParameters, 0, 0, dsResults, dsMessage) Then
.DataSource = dsResults.Tables(0).DefaultView
End If
.DataBind()
.Items.FindByValue(intCountyIdent.ToString).Selected = True
End With
End Sub