<table runat=server align=center id="Table1">
///////
后置代码中
//////
TableRow TR = new TableRow();
TableCell TD1 = new TableCell();
TD1.ID = "xxx";
TR.Cells.Add( TD1 );
Table1.Rows.Add( TR );
///////
后置代码中
//////
TableRow TR = new TableRow();
TableCell TD1 = new TableCell();
TD1.ID = "xxx";
TR.Cells.Add( TD1 );
Table1.Rows.Add( TR );
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
TableRow TR=new TableRow();
TR.ID="tr1";
TableCell TD=new TableCell();
TD.Text="kick";
TR.Cells.Add(TD);
Table1.Rows.Add(TR);
}**************************************************************************
D:\webApp\Proj_SetPlan\WebForm3.aspx.cs(30): 参数“1” : 无法从“System.Web.UI.WebControls.TableRow”转换为“System.Web.UI.HtmlControls.HtmlTableRow”D:\webApp\Proj_SetPlan\WebForm3.aspx.cs(30): 与“System.Web.UI.HtmlControls.HtmlTableRowCollection.Add(System.Web.UI.HtmlControls.HtmlTableRow)”最匹配的重载方法具有一些无效参数
for(int i=0;i<6;i++)
{
TableRow r=new TableRow();
for(int j=0;j<=6;j++)
{
TableCell c=new TableCell ();
c.Controls .Add (new LiteralControl ("("+i.ToString ()+","+j.ToString ()+")"));
r.Cells .Add (c)
c.Text=(i*j).ToString();
}
Table1.Rows .Add (r);
}
why ?
我用的table是这样的。
我是在table里放一个PlaceHolder,然后在后台象PlaceHolder添加对象来动态添加table中的行和控件(文本框)
我的代码如下:
<tr><td colSpan="2"><asp:placeholder id="phChoice" runat="server" EnableViewState="True"></asp:placeholder></td></tr>
后台代码如下:
rbChoice,txbChoice是我自己定义的控件phChoice.Controls.Add(new LiteralControl("<tr><td width='65'>"));//向PlaceHolder添加控件
phChoice.Controls.Add(rbChoice);
phChoice.Controls .Add (vRequireField);
phChoice.Controls.Add(new LiteralControl("</td><td align='middle' width='485'>"));
phChoice.Controls.Add(txbChoice);
phChoice.Controls.Add(new LiteralControl("</td></tr>"));
TR.ID="tr1";
HtmlTableCell TD=new HtmlTableCell();
TD.InnerText="kick";
TR.Cells.Add(TD);
Table1.Rows.Add(TR);