Hi,
I am creating a page that has two dropdowns. One drop down needs to change dynamically depending on the selection made in the other.
So Dropdown2 values depend on dropdown1 selection. To do this I am trying to add code to the Dropdown1_SelectedIndexChanged event.
The data comes in from Access. Both dropdowns are databound using asp accessdatasource declarative tags.
So when I handle the _SelectedIndexChanged event do I need to programmatically create another accessdatasource object and start all over? Or can I use the accessdatasource object that was created declaratively?

Thanks.

Nevermind. I figured it out. I will post the solution soon.

Here's the code as promised:

Code-behind:

Protected Sub <dropdownlist1name>_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles <dropdownlist1name>.SelectedIndexChanged
        Dim <variable> As String
        <variable> = <dropdownlist2accessdatasource>.SelectParameters(0).Name()
        <dropdownlist2accessdatasource>.SelectCommand = "select * from a where b = <variable> "

Inline -code:

<asp:AccessDataSource 
	runat="server" 
	ID="dropdownlist2datasource" 
	DataFile="accessdb.mdb" 
	SelectCommand="SELECT  * FROM a where b= @variable">
	 <SelectParameters>
      <asp:ControlParameter 
      ControlID="dropdownlist1" 
      Name=<varible> 
      PropertyName="SelectedValue" 
      Type="String" />
   </SelectParameters>

In addition to this, set AutoPostBack="True" on the dropdownlist that triggers the second dropdown.

mark as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.