table-表格
动态建立表格
protected void Button1_Click(object sender, EventArgs e)
{
int r = int.Parse(DropDownList1.SelectedValue);
int c = int.Parse(DropDownList2.SelectedValue);
for (int i = 1; i <= r; i++)
{
TableRow tr = new TableRow();
for (int j = 1; j <= c; j++)
{
TableCell tc = new TableCell();
if (i == 1)
{
tc.Controls.Add(new LiteralControl("net"));
}
else
{
Label lbl = new Label();
lbl.Text = i.ToString() + "," + j.ToString();
tc.Controls.Add(lbl);
if (lbl.Text == "2,3")
{
Image img = new Image();
img.ImageUrl = "~/img/baidu.gif";
tc.Controls.Add(img);
}
}
tr.Cells.Add(tc);
}
Table1.Rows.Add(tr);
}
{
int r = int.Parse(DropDownList1.SelectedValue);
int c = int.Parse(DropDownList2.SelectedValue);
for (int i = 1; i <= r; i++)
{
TableRow tr = new TableRow();
for (int j = 1; j <= c; j++)
{
TableCell tc = new TableCell();
if (i == 1)
{
tc.Controls.Add(new LiteralControl("net"));
}
else
{
Label lbl = new Label();
lbl.Text = i.ToString() + "," + j.ToString();
tc.Controls.Add(lbl);
if (lbl.Text == "2,3")
{
Image img = new Image();
img.ImageUrl = "~/img/baidu.gif";
tc.Controls.Add(img);
}
}
tr.Cells.Add(tc);
}
Table1.Rows.Add(tr);
}