Search code examples
asp.netdata-bindinglistboxpostbackdynamic-rebinding

Rebind to asp:Listbox on postback


When a postback occurs on my page, changes are made in my database and I want those changes to be reflected in my ListBox. It has a datasource that is set up in the .aspx side of things (DataSource = "myDataSource"). Right now, on a postback, these changes are not visible. How can I "Rebind" my ListBox?


Solution

  • try this :

    In your event handler that is causing the postback try adding this at the end (say Button1_Click if it a postback caused by a button)

    ListBox1.DataBind();
    

    it should cause the datasource to refresh.