ItemCommand on Dynamically built DataGrid not firing

Discussion in 'ASP .Net Datagrid Control' started by RCorona, Dec 21, 2004.

  1. RCorona

    RCorona Guest

    I have a page on which I build one to many grids in a for loop depending on
    the results of a sql query. Within each row of each grid I add a link button
    to get details of that record. When you click on the button the post back
    occurs but the item command does not fire. See the example of the code below.

    Any help would be apprciated, thanks.

    <code>
    DataGrid dg = new DataGrid();

    dg.EnableViewState = true;
    dg.ItemCommand += new DataGridCommandEventHandler(dg_ItemCommand);
    dg.AutoGenerateColumns = false;

    BoundColumn dcPrgId = new BoundColumn();
    dcPrgId.DataField = "ProgramId";
    dcPrgId.Visible = false;
    dcPrgId.ReadOnly = true;
    dg.Columns.Add(dcPrgId);

    TemplateColumn dcPayment = new TemplateColumn();
    dcPayment.HeaderText = "Monthly Payment";
    dcPayment.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
    dcPayment.ItemTemplate = new FormatedItemTemplate("Payment",
    "{0:c}");
    dcPayment.ItemStyle.Width = new Unit("120px");
    dcPayment.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
    dg.Columns.Add(dcPayment);

    ButtonColumn btnClosingCosts = new ButtonColumn();
    btnClosingCosts.HeaderText = "Costs";
    btnClosingCosts.HeaderStyle.HorizontalAlign =
    HorizontalAlign.Center;
    btnClosingCosts.ButtonType = ButtonColumnType.LinkButton;
    btnClosingCosts.Text = "View Details";
    btnClosingCosts.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
    btnClosingCosts.CommandName = "Costs";
    dg.Columns.Add(btnCosts);

    dg.DataSource = vRates;
    dg.DataBind();

    </code>
     
    RCorona, Dec 21, 2004
    #1
    1. Advertisements

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. Michael

    Repeater ItemCommand not firing

    Michael, Nov 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,359
    Michael
    Nov 15, 2004
  2. =?Utf-8?B?RGVlcGVzaA==?=

    Datagrid ItemCommand Event Not Firing

    =?Utf-8?B?RGVlcGVzaA==?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    6,205
    =?Utf-8?B?RGVlcGVzaA==?=
    Oct 6, 2005
  3. =?Utf-8?B?ZGFuYw==?=

    DataGrid ItemCommand event not firing if not first page

    =?Utf-8?B?ZGFuYw==?=, Oct 26, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    4,364
    =?Utf-8?B?ZGFuYw==?=
    Oct 26, 2005
  4. Andy
    Replies:
    0
    Views:
    520
  5. PD
    Replies:
    0
    Views:
    490
  6. RCorona

    ItemCommand on dynamically built DataGrid

    RCorona, Dec 21, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    171
    RCorona
    Dec 21, 2004
  7. RCorona
    Replies:
    1
    Views:
    279
    Al Cadalzo
    Jan 1, 2005
  8. John

    ImageButton not firing ItemCommand event for the datagrid

    John, Aug 4, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    408
Loading...