日期:2014-05-17 浏览次数:20465 次
for (int i = 0; i < Page.Controls.Count; i++) { foreach (System.Web.UI.Control control in Page.Controls[i].Controls) { if (control is Repeater) //这里判断是否是Repeater型,可是遍历到最后也没找到Repeater型的。。。 { Repeater repeater = (control as Repeater); int num = int.Parse(repeater.ID.Substring(repeater.ID.Length - 1, repeater.ID.Length)); if (hashTable.ContainsKey(num)) { repeater.DataSource = (IList<Info>)hashTable[num]; repeater.DataBind(); } else { repeater.Visible = false; } } } }
这样试试: foreach (System.Web.UI.WebControls.Repeater rep in Page.Controls) { }
------解决方案--------------------
foreach (Control objRepeater in this.form1.Controls) { if (objRepeater.GetType().Name == "Repeater") { //找到 } }
------解决方案--------------------
天回帖即可获得10分可用分!小技巧: