动态生成表格的问题,请教大虾们。。
private void BtnProTable_Click(object sender, System.EventArgs e)
{
int row=0;
int numrows=Int32.Parse(DrpRowNum.SelectedValue);
int numcells=Int32.Parse(DrpCelNum.SelectedValue);
for(int i=0;i <numrows;i++)
{
HtmlTableRow r= new HtmlTableRow();
if(row%2==1)
r.BgColor= "Blue ";
row++;
for(int j=0;j <numcells;j++)
{
HtmlTableCell c = new HtmlTableCell();
c.Controls.Add(new LiteralControl( "行 "+i.ToString()+ "列 "+j.ToString()));
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
}
在html里我有个table1,运行显示错误:
1.“System.Web.UI.WebControls.TableRowCollection.Add(System.Web.UI.WebControls.TableRow)”最匹配的重载方法具有一些无效参数
2.无法从“System.Web.UI.HtmlControls.HtmlTableRow”转换为“System.Web.UI.WebControls.TableRow”
请高手指教,在这先谢了!
------解决方案--------------------HtmlTableRow r= new HtmlTableRow();
改为
TableRow r= new TableRow();
------解决方案--------------------protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
private void btnCrwTable_Click(object sender, System.EventArgs e)
{
int row = Int32.Parse(selRow.Value);
int col = Int32.Parse(selCol.Value);
HtmlTable table = new HtmlTable();
table.Border = 1;
table.CellPadding=0;
table.CellSpacing= 0;
for(int i;i < row ; i++)
{
HtmlTableRow tr = new HtmlTableRow();
for(int j;i <col;i++)
{
HtmlTableCell td = new HtmlTableCell();
td.InnerHtml = " ";
tr.Controls.Add(td);
}
table.Rows.Add(tr);
}
PlaceHolder1.Controls.Add(table);
}