Search code examples
c#asp.netdropdownbox

Drop Down Control Selected Index change event


In my webfrom in asp.net I have a grid view a button, a text box and a Dropdownlist. I have a method like this to call and select the data in to my grid view.

public void fillGridByAuthor(string searchKey)
{
    GVDetails.DataSource = new ViewAllBKByAuthorOP().searchAuthorByAUNM(searchKey);
    GVDetails.DataBind();
}

This is my business layer method.

 public DataTable searchAuthorByAUNM(string searchKey)
{
    string query2 = "EXEC SelectBooksDTByAuthor'" + searchKey + "'";
    return new DataAccessLayer().executeTable(query2);
}

I'm calling fillGridByAuthor method in form in the drop downlist selected index change event like this.

 protected void DDAuthor_SelectedIndexChanged(object sender, EventArgs e)
 {
    fillGridByAuthor(DDAuthor.Text);

 }

and in the button click event like this

 protected void btnSearch_Click(object sender, EventArgs e)
 {
     fillGridByAuthor(txtAuName.Text);

 }

It is working fine when the button is clicked. Though I select the same Item in the drop down list, it doesn't give me the same output. What's incorrect here?


Solution

  • Just set AutoPostBack property of your dropdownlist to true and it will work like a charm.