Einem SharePoint Webpart dynamische Controls hinzufügen.
Auf der aspx Seite muss nur noch die Tabelle zusätzlich konfiguriert sein.
<asp:Table ID="tbl" runat="server"></asp:Table>
// Fetch the number of Rows and Columns for the table
// using the properties
int tblRows = 5;
int tblCols = 5;
// Now iterate through the table and add your controls
for (int i = 0; i < tblRows; i++)
{
TableRow tr = new TableRow();
for (int j = 0; j < tblCols; j++)
{
TableCell tc = new TableCell();
TextBox txtBox = new TextBox();
txtBox.ID = "txt-" + i.ToString() + "-" + j.ToString();
txtBox.Text = "RowNo:" + i + " " + "ColumnNo:" + " " + j;
// Add the control to the TableCell
tc.Controls.Add(txtBox);
// Add the TableCell to the TableRow
tr.Cells.Add(tc);
}
// Add the TableRow to the Table
tbl.Rows.Add(tr);
tbl.EnableViewState = true;
ViewState["tbl"] = true;
}
Kommentare zum Snippet