F
Faredoon Irani via .NET 247
Hi,
I have to display many DataGrids in one page, but at design-timeI do not know how many DataGrids there are going to be. So I amconstructing them in the code-behind. The problem here is, Ialso want a event-handler for the ItemCommand event of each ofthose DataGrids. For this, I am aware that just declaring theevent using:
DataGrid1.ItemCommand += newDataGridCommandEventHandler(DataGrid1_ItemCommand);
is fine. but this doesn't always get fired in my case becausethis variable "DataGrid1" is one that is going to getinstantiated many times in a loop like this:
DataGrid1 = new System.Web.UI.WebControls.DataGrid();
The variable is a protected class member. This will result in alot of un-disposed DataGrid objects because I never call theDispose() method on any of them - If I do so, the DataGrid willnot get displayed at all! I was thinking of using a collectionclass to dump all the Datagrid objects and Clear the collectionon Page_Load (that is where I am constructing the DataGrids,binding the Data and so on ). But is that possible? the majorproblem here is of the ItemCommand event-handler not gettingcalled. I am checking for a "IsPostBack" in Page_Load andappropriately constructing the grids.
Help needed, please...
I have to display many DataGrids in one page, but at design-timeI do not know how many DataGrids there are going to be. So I amconstructing them in the code-behind. The problem here is, Ialso want a event-handler for the ItemCommand event of each ofthose DataGrids. For this, I am aware that just declaring theevent using:
DataGrid1.ItemCommand += newDataGridCommandEventHandler(DataGrid1_ItemCommand);
is fine. but this doesn't always get fired in my case becausethis variable "DataGrid1" is one that is going to getinstantiated many times in a loop like this:
DataGrid1 = new System.Web.UI.WebControls.DataGrid();
The variable is a protected class member. This will result in alot of un-disposed DataGrid objects because I never call theDispose() method on any of them - If I do so, the DataGrid willnot get displayed at all! I was thinking of using a collectionclass to dump all the Datagrid objects and Clear the collectionon Page_Load (that is where I am constructing the DataGrids,binding the Data and so on ). But is that possible? the majorproblem here is of the ItemCommand event-handler not gettingcalled. I am checking for a "IsPostBack" in Page_Load andappropriately constructing the grids.
Help needed, please...