p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional C#, 2nd and 3rd Editions (http://p2p.wrox.com/forumdisplay.php?f=44)
-   -   Dynamic Button Generation (http://p2p.wrox.com/showthread.php?t=26418)

LouMattera March 4th, 2005 03:07 PM

Dynamic Button Generation
 
Iam building a dynamic table with 5 cells. The first cell will be a button to be used to select that row. I am not having a problem creating the table row by row. However I can not figure out how to capture the event when the button in cell is pressed.
code sample
----------
TableRow tblRow = new TableRow();
TableCell[] tblCell - new TableCell[5];
tblCell[0] = new TableCell();
tblCell[1] = new TableCell();
..
..
tblCell[4] = new TableCell();

SelButton = new Button();
SelButton.ID = "SelBtn";
SelButton.CommandArg = "Select";
tblCell[0].Controls.Add(SelButton);
// add remaining cells
tblRow.Cells.AddRange(tblCell);
Table1.Rows.Add(tblRow);

I can not figure out how I dynamically add the
'OnCommand = "CommandBtn_Clicked" ' to the button.

Any and all help is welcomed.



bmains March 4th, 2005 03:40 PM

SelButton.Click += new EventHandler(SelButton_Click);

Define an event SelButton_Click in your code then. Or you may have to look at event bubbling.

Brian

LouMattera March 4th, 2005 04:26 PM

Thanks but that did not work.

If I put the following line in the aspx file it works, I need to put this line in dynamically.

<asp:TableRow>
 <asp:TableCell>
  <asp:Button OnCommand="CommandBtn_Clicked" Width="20px" Runat="server"></asp:Button></asp:TableCell></asp:TableRow>




All times are GMT -4. The time now is 01:27 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.