I am stuck with a simple problem but not able to figure out the solution
I have an asp.net application that queries some data from data reader based on filters and updates in a listbox when Done button is pressed. The problem is that if i modify the selection and press Done again, the old values are still present i.e. I get old results and the new ones are appended. How do remove the old values so that everytime I modify my selection I get only the new values.
I am stuck with a simple problem but not able to figure out the
Share
First, if you’re loading the values in Page_Load, be sure to surround your loading code with an
if(!Page.IsPostback)statement to ensure you’re not re-binding it on every load. (See the ASP.NET Page Lifecycle for details.)(Alternatively, you can bind it on every page load in Page_Init instead of Page_Load, which will allow you to bind it and have the user-entries be applied when the Viewstate is applied. Again, see the Page Lifecycle for details. Or this great article.)
Next, ensure that you are calling the Clear() command on the listbox to remove items.