DropDownList - IndexChanged

M

mosscliffe

I am trying to use IndexChanged of DropDownList to control the next
part of my site.

The problem I have is that the 'indexchanged' is not getting called if
I select the first entry on first displaying of DDL.

Similarly if I re-select the previous selection with the mouse, it
still does not recognise, it as having changed.

I tried setting 'selectedindex' to -1, but that did not cure the
problem, but added to the confusion, by not allowing indexvalue 0 to
ever be selected.

Can anyone show me the correct way to use 'indexchanged'

I have Autopostback = TRUE, because without that it never got called.
 
S

Scott

Can you post the code? Maybe there is a missing Handles clause (in the
case of a VB.NET event.)
 
M

mosscliffe

Thanks for your interest

The code is as follows

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not IsPostBack Then

Dim patterns As New ArrayList
patterns.Add("*.txt")
patterns.Add("*.csv")
patterns.Add("*.unl")
patterns.Add("*.uxw")

Dim root As String = Server.MapPath(".") & "\MyData\"
Dim patt As String
DropDownList1.Items.Clear()
For Each patt In patterns

Dim files() As String =
System.IO.Directory.GetFiles(root, patt)
'Dim sb As New System.Text.StringBuilder(2048)
Dim filename As String
Dim f As String
For Each f In files
filename = System.IO.Path.GetFileName(f)
DropDownList1.Items.Add(filename)
Next
Next

DropDownList1.SelectedIndex = -1
lblDebug.Text += "PageLoad: NotPostBack" &
DropDownList1.SelectedItem.Text & "<BR />"
Else
lblDebug.Text += "PageLoad: IsPostBack" &
DropDownList1.SelectedItem.Text & "<BR />"
End If


End Sub

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged

Dim strFname As String = DropDownList1.SelectedItem.Text
Dim fw As New System.IO.StreamReader(Server.MapPath("MyData/" &
strFname), True)
TextBox1.Text = fw.ReadToEnd()
fw.Close()
fw.Dispose()
lblUploaded.Text = "Loaded: " & strFname
DropDownList1.SelectedIndex = -1

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top