在后台用C#枚举控件不像javascript那么简单,HasControls只能抓到直属下级的控件,如果有多个div,table嵌套,就要递归了
public static void CloseAllContent(System.Web.UI.Control page,bool bOpen)
{
int nPageControls = page.Controls.Count;
for (int i = 0; i < nPageControls; i++)
{
foreach (System.Web.UI.Control control in page.Controls[i].Controls)
{
if (control.HasControls())
{
CloseAllContent(control,bOpen);
}
else
{
if (control is TextBox)
{
// (control as TextBox).Text = "";
(control as TextBox).Enabled = bOpen;
}
if (control is CheckBox)
{
// (control as CheckBox).Checked = false;
(control as CheckBox).Enabled = bOpen;
}
if (control is RadioButtonList)
{
//(control as RadioButtonList).SelectedIndex = -1;
(control as RadioButtonList).Enabled = bOpen;
}
if (control is RadioButton)
{
// (control as RadioButton).Checked = false;
(control as RadioButton).Enabled = bOpen;
}
if (control is CheckBoxList)
{
foreach (ListItem item in (control as CheckBoxList).Items)
{
item.Selected = bOpen;
}
}
if (control is Button)
{
(control as Button).Enabled = bOpen;
}
}//if..else
}//foreach
}//for
}