registering events for dynamically declared DataGrids

  • Thread starter Faredoon Irani via .NET 247
  • Start date
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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top