registering events for dynamically declared DataGrids

Discussion in 'ASP .Net Web Controls' started by Faredoon Irani via .NET 247, Aug 5, 2004.

  1. 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...
    --------------------------------
    From: Faredoon Irani

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>jeJnnd00PUCwYJw05pwXog==</Id>
    Faredoon Irani via .NET 247, Aug 5, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Helen
    Replies:
    2
    Views:
    4,272
    bruce barker
    Sep 30, 2004
  2. JohnZing

    declared or not declared ?

    JohnZing, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,571
    Jon Paal
    Feb 5, 2006
  3. Juan T. Llibre
    Replies:
    2
    Views:
    3,863
    =?Utf-8?B?UmljaA==?=
    Dec 16, 2006
  4. Mike
    Replies:
    0
    Views:
    744
  5. Anna Schmidt
    Replies:
    1
    Views:
    306
    Alvin Bruney [MVP]
    Feb 27, 2004
Loading...

Share This Page