Table控件拖一个到窗体作为动态表格的容器,设置一下相关属性,比如BorderStyle什么的。拖两个TextBox,一个按钮过去,然后在按钮的Click事件里编写下边的代码。。。
protected void Button1_Click(object sender, EventArgs e)
{
int rowCnt;
int rowCtr;
int cellCtr;
int cellCnt;
rowCnt = int.Parse(TextBox1.Text);
cellCnt = int.Parse(TextBox2.Text);
for (rowCtr = 1; rowCtr <= rowCnt; rowCtr++)
{
TableRow tRow = new TableRow();
Table1.Rows.Add(tRow);
for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++)
{
TableCell tCell = new TableCell();
tCell.Text = "行" + rowCtr + ",列" + cellCtr;
tRow.Cells.Add(tCell);
}
}
}