简体   繁体   中英

Refresh gridview after change in dropdownlist

I have a gridview, that shows record according to the selected value in the dropdownlist. This works, on pageload the gridview only contains the records that it should contain. But after choosing a different option in the dropdownlist, the gridview does not change. I've tried fixing it with this:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridView1.DataBind();
}

But that does not work. I believe it's a very small matter, but after googling it I can't figure out what to do.

It's hard to tell what you're currently doing from the code you've posted but typically you'd need to -

  • Get the value from the drop down
  • Query your data using using the new value
  • Bind the resulting data to your datasource

The code you've posted looks as if it's only doing a bind of the already existing data to the GridView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM