Creare tabella da codice - click celle
Come creare una tabella da codice (dinamicamente) con celle cliccabili
Create a Table dynamically from code with clickable cell
In questo esempio viene mostrato come creare una tabella dinamicamente da codice con celle cliccabili.
>>
File Default.aspx
<asp:Label ID="Label_Msg" runat="server" />
<asp:Table ID="Table_Tasti" runat="server"
CellPadding="5"
Width="50%"
</asp:Table>
File Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
Int32 righe = 5;
Int32 colonne = 5;
for (int i = 0; i < righe; i++)
{
TableRow riga = new TableRow();
for (int j = 0; j < colonne; j++)
{
TableCell cella = new TableCell();
Button bt = new Button();
bt.ID = i + "-" + j;
bt.Text = i + "-" + j;
bt.Style.Add("width", "100%");
bt.Style.Add("height", "60px");
bt.Click += new EventHandler(bt_Click);
cella.Controls.Add(bt);
riga.Cells.Add(cella);
}
Table_Tasti.Controls.Add(riga);
}
}
protected void bt_Click(object sender, EventArgs e)
{
Button buttonClick = (Button)sender;
Label_Msg.Text = buttonClick.ID;
}