[RESOLVED] dropdownlist SelectionChange
I have some constant arraylists that are filled when a dropdownlist value is changed (based on the value of the DDL). When the first DDL is changed, I have a second DDL that binds to the values of the constant arraylist. However I ran the code and change the value of the ddl but it doesn't databind to the second DDL. Do I have to refresh the page? And if so how can I tell it to keep the selectedvalue of the first dropdownlist that was fires the SelectedIndexChanged event?
VB Code:
Private Sub ddlSection_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSection.SelectedIndexChanged
If ddlSection.SelectedItem.Text = "500" Then 'this is the first ddl
'Section500
arrSection500.Clear()
arrSection500.Add("Select Form")
arrSection500.Add("500-10")
arrSection500.Add("500-10C")
arrSection500.Add("500-11")
ddlForm.DataSource = arrSection500 'this is the second ddl i want to bind this arraylist to
ddlForm.DataBind()
End If
THanks again!!
Re: dropdownlist SelectionChange
I write in C#, not VB, so the code is slightly different, but my event contains the following code and executes perfectly:
VB Code:
System.Collections.ArrayList oAL = new ArrayList(0);
oAL.Add("== Please Choose ==");
oAL.Add("500-10");
oAL.Add("500-10C");
oAL.Add("500-11");
ddlForm.DataSource = oAL;
ddlForm.DataBind();
Re: dropdownlist SelectionChange
aah thanks!
another problem I'm having is I need my dropdownlist to be the value of a parameter in the url if the parameter exists, but it doesn't seem to work. Here's my code
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
If Request.QueryString("section") = "" Then
ddlSection.SelectedIndex = -1
Else
ddlSection.SelectedItem.Value = Request.QueryString("section")
End If
End If
End Sub
Right now when the parameter equals something, my ddl still goes to my default value and not my value of my parameter.
Re: dropdownlist SelectionChange
foreach x as listitem in ddlSection.items
if x.Value = Request.QueryString("section") then
x.selected=true
exit for
endif
next
Re: dropdownlist SelectionChange
Thanks for the suggestion, what I did though was set AUTOPOSTBACK on and when it loads it grabs its value i was setting the parameter as from a different control
Thanks for all the help!