I have a drop down list on my my aspx page. This box is populated from my sqlserver db. I want to allow people to search based on the value they select from the drop down list. The problem I am encountering is that it always returns the value of the first item in my list box. I am guessing my problem spurs from my lack of knowledge of postback, please help me.

This is the code im trying to use to retrieve the value of the ddl and use it as a parameter for another method.

protected void btnTypeSearch_Click(object sender, EventArgs e)

                string type = ddType.SelectedItem.Text;

                DataLayer typeLayer = new DataLayer();
                DataTable dt = typeLayer.fillTbl("SELECT * FROM Trees WHERE Type='" + type + "'");


In reality I simply need a way to store the value of the currently selected item in a variable for future use.

8 Years
Discussion Span
Last Post by __avd


If you are loading DropDownList in Page_Load event then the code of databinding must be execute once.

IsPostBack property of Page class is used to determine whether a page is loaded first time or not.

You may add your databind code like this:

if(IsPostBack==false) {
       ..  Place your databind code here..
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.