I am developing a SharePoint 2010 non-visual WebPart which displays some kind of data in a big table. The table rows should be filtered by selecting a filter criterium from a DropDownList which is part of the webpart.
The OnSelectedIndexChanged event of the DropDownList is fired after CreateChildControls and before OnPreRender. Because the cells of the table contain LinkButtons with an OnClick event attached, they must be created in CreateChildControls in order to get the OnClick events fired.
I don't know which rows of the table to hide until the OnSelectedIndexChanged of the DropDownList is fired, so I create all possible table rows in CreateChldControls and try to remove the filtered ones later in OnSelectedIndexChanged the event directly or in OnPreRender. The rows were physically removed from the parent Table's control collection, but they are nevertheles displayed.
As a test, I tried to remove some random rows at the end of the CreateChildControls method after creating them, it worked and the rows were not rendered.
How I remove the rows:
Table mt = FindControl("matrixtable") as Table;
Helpers.Log("Controls in Table: " + mt.Controls.Count);
foreach (int kdid in kdIdsInvisible)
{
TableRow c = mt.FindControl("kdrow" + kdid) as TableRow;
Helpers.Log(c.ID);
mt.Controls.Remove(c);
}
Helpers.Log("Controls in Table: " + mt.Controls.Count);
Output:
Controls in Table: 88
Controls in Table: 2
But all rows are still rendered...
Is there a solution for this? Thank you in advance!