Hi,
I'm working on a module and have decided to use a datagrid. In my datagrid I have to display a variable number of columns as the underlying data is a matrix that cross references weekends vs teams in a schedule type display. I can get my table to render properly when autogenerate columns is on and I pass the table into it. I can even get the formatting etc working properly. My intial problem was that I wanted some of my dynamic column to have working link buttons and images in them.
First attempt was that i would add a link button and my images on the databound event, that worked, but it doesn't persist on postback becuase the controls are only added on databinding. I then added the controls in the datagrids item created event. This would make the first display of my grid databound without my controls. Then when I would click another link button on the page it would refresh and not show the data, but show my empty controls added during the item created event.
The answer would of course be a template column. I've used them before through asp.net and they work great, this is of course a different aproach when adding them through code. After figuring out how to create the template column class, bind it to the template column and add that to my datagrid I tried my app. It worked, but when I press one of the link buttons the dynamic columns disappear.
I then tried building my columns in the page_init event. That works great but I can't run my sql query to get the underling data until I have a drop down list values. If i try to get the value of that control in the page_init event it gives me a null reference exception.
I know that I have to add my columns in at a stage in which the datagrid's viewstate is not yet applied to the table but i cannot find any resources that help me. I need my database query to be ran prior to binding my columns but I need the values from a drop down list before I can run my query. What event/stage can I put my code in to ensure that the columns are created in the right order.