这对我有用了大约5分钟,现在我什么都没有。对象是从下拉列表中选择一个数字,然后使用该数字来指定将向表中添加的行数。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//variables for the number of rows and cells
int numrows = int.Parse(DropDownList1.SelectedValue);
int numcells = 3;
for (int j = 0; j < numrows; j++)
{
HtmlTableRow r = new HtmlTableRow();
r.BgColor = "Gainsboro";
//demoTable.Rows.Add(r);
for (int i = 0; i < numcells; i++)
{
HtmlTableCell c = new HtmlTableCell();
c.InnerHtml = " row " + j.ToString() + ", cell " + i.ToString();
r.Cells.Add(c);
}
demoTable.Rows.Add(r);
}
}
}