62,046
社区成员
发帖
与我相关
我的任务
分享
using System.Collections.Generic;
using System.Web.UI;
static public class Extensions
{
static public IEnumerable<T> Cast<T>(this Control ctrl) where T : Control
{
foreach (Control x in ctrl.Controls)
if (x is T)
yield return (T)x;
foreach (Control x in ctrl.Controls)
foreach (var r in Cast<T>(x))
yield return r;
}
}
protected void Page_Load(object sender, EventArgs e)
{
var cs = from Button b in this.form1 where b.Text.StartsWith("B") select b;
Page.ClientScript.RegisterStartupScript(this.GetType(), "result", "alert('找到" + cs.Count().ToString() + "个符合条件的按钮。');", true);
}