动态生成控件取ID的问题 我问一下怎么给动态产生的控件加runat属性啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected void Page_Load(object sender, EventArgs e) { HtmlTable htmlTable = new HtmlTable(); htmlTable.ID = "HtmlTable1"; HtmlTableCell htmlTableCell = new HtmlTableCell(); htmlTableCell.InnerHtml = "Name"; HtmlTableRow htmlTableRow1 = new HtmlTableRow(); htmlTableRow1.Cells.Add(htmlTableCell); htmlTable.Rows.Add(htmlTableRow1); HtmlTableRow htmlTableRow2= new HtmlTableRow(); HtmlTableCell htmlTableCell2 = new HtmlTableCell(); htmlTableCell2.InnerHtml = "chen"; htmlTableRow2.Cells.Add(htmlTableCell2); htmlTable.Rows.Add(htmlTableRow2); this.form1.Controls.Add(htmlTable); } protected void Button2_Click(object sender, EventArgs e) { HtmlTable htmlTable = (HtmlTable)this.form1.FindControl("HtmlTable1"); Response.Write(htmlTable.Rows[1].Cells[0].InnerHtml.ToString()); } 先感谢楼上的基本回答,runat=‘server’ 我已经加上,下面是自动生成的tablepage_load(){ InitTable() //生成自定义表} 点击save button后,获取a,b的value,TextBox txt = (TextBox)this.form1.FindControl("090de4b3-f174-448e-b0bb-cf458454f816");但返回的是null,很奇怪,我去find这个Table的ID,却能找到 :( <table id="752cb166-99f2-4768-a89a-dcc25d196bb4" style="width:98%;" width="98%" border="0" cellpadding="0" cellspacing="0"><tr style="background-color:#cccccc;"><td colspan="5" align="left">test1</td></tr><tr class="edit"><td width="100">a:</td><td><input name="ctl08" type="text" value="aaa" maxlength="12" runat="server" id="090de4b3-f174-448e-b0bb-cf458454f816" /></td><td width="100">b:</td><td><input name="ctl11" type="text" maxlength="12" runat="server" id="a4f78481-40fc-4adf-833f-2c5a32bad4d3" /></td></tr><tr></tr></table> ie 8变慢 基本上打不开了 DROPDOWNLIST 关联后,获取多个数据问题! 怎樣在一個空間運行多個.net的網站? 求 sql 语句 vs2005 下用ajax需要做什么设置 求一个正则表达式:) 各位高手,帮小妹看看这是怎么了?急! 在Repeater中如何显示和隐藏区域(div)数据? 怎么用正则表达式来取文本: 编号 产品名称 价格 参考价 进价 三楼楼长的oa如何修改成用oracle数据库 求Infragistics NetAdvantage 2006 Volume 2 source(For CLR1) 急!!!System.Xml.XmlDocument问题
protected void Page_Load(object sender, EventArgs e)
{
HtmlTable htmlTable = new HtmlTable();
htmlTable.ID = "HtmlTable1"; HtmlTableCell htmlTableCell = new HtmlTableCell();
htmlTableCell.InnerHtml = "Name";
HtmlTableRow htmlTableRow1 = new HtmlTableRow();
htmlTableRow1.Cells.Add(htmlTableCell);
htmlTable.Rows.Add(htmlTableRow1);
HtmlTableRow htmlTableRow2= new HtmlTableRow();
HtmlTableCell htmlTableCell2 = new HtmlTableCell();
htmlTableCell2.InnerHtml = "chen";
htmlTableRow2.Cells.Add(htmlTableCell2);
htmlTable.Rows.Add(htmlTableRow2); this.form1.Controls.Add(htmlTable);
} protected void Button2_Click(object sender, EventArgs e)
{
HtmlTable htmlTable = (HtmlTable)this.form1.FindControl("HtmlTable1");
Response.Write(htmlTable.Rows[1].Cells[0].InnerHtml.ToString());
}
{
InitTable() //生成自定义表
}
点击save button后,获取a,b的value,
TextBox txt = (TextBox)this.form1.FindControl("090de4b3-f174-448e-b0bb-cf458454f816");
但返回的是null,很奇怪,我去find这个Table的ID,却能找到 :(
<table id="752cb166-99f2-4768-a89a-dcc25d196bb4" style="width:98%;" width="98%" border="0" cellpadding="0" cellspacing="0">
<tr style="background-color:#cccccc;">
<td colspan="5" align="left">test1</td>
</tr>
<tr class="edit">
<td width="100">a:</td>
<td><input name="ctl08" type="text" value="aaa" maxlength="12" runat="server" id="090de4b3-f174-448e-b0bb-cf458454f816" /></td>
<td width="100">b:</td>
<td><input name="ctl11" type="text" maxlength="12" runat="server" id="a4f78481-40fc-4adf-833f-2c5a32bad4d3" /></td>
</tr>
<tr>
</tr>
</table>