获取动态添加控制标识 [英] Get Id of dynamically added control
本文介绍了获取动态添加控制标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个HTML表表,并补充控制它在运行时为:
i have one html table "table "and added controls it at run time as :
HtmlTableRow tabelrow = new HtmlTableRow();
HtmlTableCell tablecell = new HtmlTableCell();
Label lbl = new Label();
tablecell.Controls.Add(lbl);
然后我想用的foreach让每个控件
then i want to get each controls by using foreach
如(在table.controls的foreach控制C)
或(在tablecell.controls的foreach控制C)
但它不工作。
such as (foreach control c in table.controls)
or (foreach control c in tablecell.controls)
but its not working.
推荐答案
试过以下。我可以用标识的控制,但你需要一个ID首先分配给它。
Tried the following. I can get the controls with the ID but you need to assign an ID to it first.
HtmlTable table = new HtmlTable();
for (int i = 0; i < 10; i++)
{
HtmlTableRow tablerow = new HtmlTableRow();
tablerow.ID = Guid.NewGuid().ToString();
HtmlTableCell tablecell = new HtmlTableCell();
tablecell.ID = Guid.NewGuid().ToString();
Label lbl = new Label();
lbl.ID = Guid.NewGuid().ToString();
tablecell.Controls.Add(lbl);
tablerow.Controls.Add(tablecell);
table.Controls.Add(tablerow);
}
List<string>RowID = new List<string>();
List<string>CellID = new List<string>();
List<string>LabelID = new List<string>();
foreach (Control Row in table.Controls)
{
//Each control will be a tablerow.
RowID.Add(Row.ID);
CellID.Add(Row.Controls[0].ID);
LabelID.Add(Row.Controls[0].Controls[0].ID);
}
究竟是什么你想怎么办?请详细说明。
What exactly are you trying to do? Please elaborate.
这篇关于获取动态添加控制标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文