ItemCommand on Dynamically built DataGrid not firing

R

RCorona

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>
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top