• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3099
  • Last Modified:

DropDownList1_SelectedIndexChanged

I have a basic drop-down list on my page, auto postback set to true... with the below simple code on the selected index changed event i put the selected index into an int variable....

selected always returns as 0 (zero) regardless of the item selected. Or if I change to use a string with SelectedValue it always returns the first item in the list... Do I have to do something special to get it working???

private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
     int selected = DropDownList1.SelectedIndex;
}
0
nahguam
Asked:
nahguam
1 Solution
 
sansofturaCommented:
I believe you are populating the DropDownList1 in pageload event. So every time the page is posted, the dropdown gets populated. Try moving inside !IsPostBack

void Page_Load()
{
    if (!IsPostBack)
    {
        populateDropdown();
    }
}
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now