My understanding of the order of page events is this:
Page : Load
Control : DataBind (for a GridView or whatever)
Control : Load
Control : Clicked (for a Button)
Page: PreRender
Control : PreRender
(There are lots of others - but these are the ones I'm interested in)
The important thing to notice here is that the button's click event comes after the gridview's bind event. If the button causes a change to the data, the GridView displays the old data. I could rebind the control in the PreRender event, but that seems totally ugly.
This must be a very common pattern (a button that updates data). How do I put this together so that the GridView binds to the data after the Button click changes it?
The answer was in the Button Click event, after the data has been changed, call DataBind() on the page to cause the GridView (and anything else that needs it) to rebind. I didn't realise you could do that.
Thank you Ocdecio & Mufasa - I would mark your answers as helpful, but I got no rep yet.