R – Web parts, dynamically created controls and eventhandlers

event handlingsharepointweb-parts

What is the best way to display, in a web part, dynamic tables where each cell can cause a postback to display a different set of data?

For example, imagine some financial data:

Table 1:  Quarters in year

         |   Q1  |  Q2  |  Q3  |  Q4  |
Things 1 |   23  |  34  |  44  |  32  |
Things 2 |   24  |  76  |  67  |  98  |

On clicking on the value for Q2, Things 1 (34), this will lead to a second table being displayed instead of Table 1:

Table 2:  Weeks in Quarter

            |   W1  |  W2  |  W3  |  W4  |  W5  |  W6  |  W7  |
SubThings 1 |   231 |  22  |  44  |  22  | 344  |  86  |  12  |
SubThings 2 |   14  |  75  |  47  |  108 | 344  |  86  |  12  |

The problem with the approach I am taking at the moment is that I can create Table 1 in CreateChildControls, which leads to all the events being wired up fine for all the linkbuttons in the cells.

However, because on the postback, I need to create Table 1 in CreateChildControls again, in order to have the eventhandlers correctly wired up, and as the events fire after CreateChildControls, I only know that I need to change the table after CreateChildControls.

Thus, wherever I create Table 2 as a resault (since its after CreateChildControls), I cant get it to wire up events correctly.

Any thoughts?

Regards
Moo

Edit: Solved it.

What you need to do is check in OnPreRender any eventhandler calls, set any flags you need to and then call this.CreateChildControls manually so the new table is created and everything is wired up correctly.

Best Answer

Looks like you are talking about a master/detail situation here. Could you not create two web parts and use web part connection to communicate the required information from table 1, in the first web part to table 2 in the second web part?

J