As a continuation of the HOW I was able to deal with dynamically creating grids based on a query, I had a problem. The problem was that that the ItemCommand was NEVER firing on postback. If you already know where I am going with this, then I’m sorry, but this was a crazy problem that was having a tough time getting to the bottom of. None of my debug code would ever hit or do anything related to that generated command button click, even though the post back happened.
When testing, I also noticed that all of my grids were disappearing on the post back, which made sense, because I had done this is usual:
protected void Page_Load(object sender, EventArgs e)
But, it appears that when the Page_Load fires on the postback and it does NOT create the control that caused the postback in the first place (my grid with a command button), it never fires the event handler! I was able to get it all to work by removing the IsPostBack check, but it seems silly to think that I am recreating the control from scratch in order to fire a button click. Almost like the button that ASP.Net is saying was clicked is gone forever and is replaced by another one which IT thinks was clicked. Kind of bizarre!!