views:

449

answers:

3

Hi,

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.

A: 

Hi Moo,

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

Jay
That solves it for two tables, but not for more than two, which i could end up doing.
Moo
A: 

Just add 2 tables to your web part, hide the second until the first has an element clicked, then set the second table's datasource in the OnClick event handler, set the second grid to visible and the first to hidden...

Colin
The problem with that is that it solves the issue for two tables, but not for three tables, or n tables.I have infact solved the issue myself, for n tables.
Moo
That wasn't clear from the question, that you needed continuous drill down. My solution would the be to create my own templated control...
Colin
A: 

At Alex's suggestion, here is the answer:

The events need to be tied up prior to them being called, so you need to create the same control in CreateChildControls, allow the event to be called and then resetup everything afterward.

To do this, first do CreateChildControls identically to the prior page, then check in OnPreRender if any eventhandler calls have been made, set any flags you need to and then call this.CreateChildControls manually with the new setup information so the new table is created and everything is wired up correctly.

Moo