<div>
新建 <asp:TextBox ID="TextBox1" runat="server" Width="26px"></asp:TextBox>个按钮
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Table ID="Table1" runat="server">
</asp:Table>
</div>
后台: protected void Button1_Click(object sender, EventArgs e)
{
int num = Convert.ToInt32(TextBox1.Text);
int a = 1;
while (a <= num)
{
TableRow tr = new TableRow();
for (int i = 0; i < 3 & a <= num; i++)
{
TableCell tc = new TableCell();
Button btn = new Button();
btn.Text = a.ToString();
tc.Controls.Add(btn);
tr.Cells.Add(tc);
a++;
Table1.Rows.Add(tr); }
} }
<asp:Button ID="createbutton" runat="server" Text="批量创建"
onclick="createbutton_Click" />
<asp:Table ID="HolderTable" runat="server"></asp:Table> protected override void OnLoad(EventArgs e)
{
CreateControl();
} protected void createbutton_Click(object sender, EventArgs e)
{
if (ViewState["CreateControl"] == null)
{
ViewState["CreateControl"] = true;
CreateControl();
}
} void CreateControl() {
if (ViewState["CreateControl"]==null) return;
for (int x = 0; x < 20; x++)
{
TableRow row = new TableRow();
for (int y = 0; y < 4; y++)
{
TableCell cell = new TableCell();
Button bt = new Button();
bt.Text = string.Format(" x={0},y={1} ", x, y);
cell.Controls.Add(bt);
row.Cells.Add(cell);
}
HolderTable.Rows.Add(row);
}
}
你的就没有解决