UniqueID,页面子控件唯一标示
aspx:
<form id="form1" runat="server">
<asp :Repeater ID="MyDataList" runat="server">
<ItemTemplate>
<asp: Label ID ="Mylbl" runat ="server"></asp: Label>
</ItemTemplate>
</asp :Repeater>
<asp :Label ID="ResultsLabel" runat="server"></asp :Label>
</form >
aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
//获取Repater 控件的命名控件
sb.Append( "Container:a" + MyDataList.NamingContainer.ToString()+"<p>" );
ArrayList arrList = new ArrayList();
arrList.Add( "a");
arrList.Add( "b");
arrList.Add( "c");
MyDataList.DataSource = arrList;
MyDataList.DataBind();
//获取数据控件中集合的个数
for (int i = 0; i < MyDataList.Controls.Count; i++)
{
Label reLb= (Label)((RepeaterItem )MyDataList.Controls[i]).FindControl("Mylbl");
//获取lbl 控件的命名控件
sb.Append( "Container:b" + ((RepeaterItem)MyDataList.Controls[i]).NamingContainer.ToString() + "@@");
//给lbl 添加唯一标示
sb.Append( "<b>" + reLb.UniqueID + "</b><p>" );
}
ResultsLabel.Text = sb.ToString();
}
运行结果:
属性注释:
作者:大胖儿在努力
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。