Listbox selectedIndexChanged doesn't fire when selecting an item from the list

danielle picture danielle · Feb 20, 2014 · Viewed 8.1k times · Source

I have a listbox that needs to be populated by directories. i have successfully filled the listbox with the Directories but my problem is i can't get the selected item's value. i placed a breakpoint on the SelectedIndexChanged event but my web application doesn't seem to run through that code.

Here is my code for populating the listbox:

        lstDirectories.DataSource = dtDirectories;
        lstDirectories.DataValueField = "DirectoryID";
        lstDirectories.DataTextField = "DirectoryName";
        lstDirectories.DataBind();

This is how i get value from the listbox on the SelectedIndexChanged Event:

        TextBox1.Text = lstDirectories.SelectedItem.Value.ToString();

am i doing something wrong here? thanks for the help! :)

Answer

Afnan Ahmad picture Afnan Ahmad · Feb 20, 2014

Use the property:-

AutoPostBack="True"

By default it is False.