I have a gridview that, upon pressing a button on the page, fills a form. In that form is a dropdown list populated from a database, and I am using an ID in the gridview to change the selected value of the dropdown list. I am running into an issue where every time I press the button it will crash and tell me the the selected value cannot be changed because that value does not exist in the dropdown list. The list is filling fine, I am seeing the appended databound names correctly.
However, I wrote a foreach loop to loop through the ddlist to see what the values were and the are all null. Yet the list itself shows up and fills correctly. What I'm guessing is that the list is filling AFTER the button event handler is called, but I don't know how to tell if that's true or not. Any pointers on how to make it so the button event handlers are called AFTER the databound values are appended to the list?
You need to bind the dropdownlist. When you bind it, only then the list will be filled and you can then check if that id exists in the list before selecting it.