ItemCommand on dynamically built DataGrid

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

  1. RCorona

    RCorona Guest

    I have a page that builds one or more datagrids dynamically, each row on each
    grid has a link button. As I build each grid I also set the event handler for
    the grid to the same method. When the button is clicked the post back
    happens, but the item command never fires. I tried to over ride the
    OnBubbleEvent but to no avail.

    Below is a snippet of the code. It is in a for loop that builds one to many
    grids.

    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();
    RCorona, Dec 21, 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. Natty Gur
    Replies:
    0
    Views:
    577
    Natty Gur
    Jun 30, 2003
  2. Mike

    DataGrid ItemCommand Event

    Mike, Oct 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    491
    Patrik Löwendahl
    Oct 24, 2003
  3. PokerJoker

    Accessing data from Dynamically built Datagrid

    PokerJoker, Aug 27, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    123
    PokerJoker
    Aug 27, 2004
  4. RCorona

    ItemCommand on Dynamically built DataGrid not firing

    RCorona, Dec 21, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    139
    RCorona
    Dec 21, 2004
  5. RCorona
    Replies:
    1
    Views:
    159
    Al Cadalzo
    Jan 1, 2005
Loading...

Share This Page