62,046
社区成员
发帖
与我相关
我的任务
分享
public int SearchControl<T>(ControlCollection controls) where T : Control
{
int count = 0;
foreach (System.Web.UI.Control control in controls)
{
if (control.Controls != null && control.Controls.Count > 0)
{
count += SearchControl<T>(control.Controls);
}
if (control is T)
{
count++;
}
}
return count;
}
Dictionary<string, int> controls = new Dictionary<string, int>();
foreach (Control c in this.Controls)
if (!controls.ContainsKey(c.ToString()))
controls.Add(c.ToString(), 1);
else
controls[c.ToString()]++;
foreach (string s in controls.Keys)
Response.Write(s + "," + controls[s].ToString() + "<br/>");
<script type="text/javascript">
function find()
{
var count = 0;
for (var i=0;i<document.form1.length;i++)
{
if (document.form1.elements[i].type=="text")
{
count++;
}
}
alert(count);
}
</script>
Dictionary<Control, int> controls = new Dictionary<Control, int>();
foreach (Control c in this.form1.Controls)
if (!controls.ContainsKey(c))
controls.Add(c, 1);
else
controls[c]++;
foreach (Control c in controls.Keys)
Response.Write(c.ToString() + "," + controls[c].ToString() + "<br/>");