日期:2014-05-18 浏览次数:20507 次
foreach (Control c in Page.Controls) { if (c.GetType().ToString() == "System.Web.UI.WebControls.RadioButton") ((RadioButton)c).Enabled = false; }
------解决方案--------------------
2楼的应该没错,不过代码写法有点不好,
//if (c.GetType().ToString() == "System.Web.UI.WebControls.RadioButton") //改为 if (c.GetType() == typeof(RadioButton))
------解决方案--------------------
//page只是一个节点.你的Radiobutton可能是在page.form节点下.所有在不确定节点是哪个的情况下最好循环遍历一下. public void SetRadioButton(Control obj) { for(int i=0;i<obj.Controls.Count;i++) { if(obj.Controls[i].Count>0) SetRadioButton(obj.Controls[i]; else { if(obj.Controls[i].GetType==typeof(RadioButton)) ((RadioButton)obj.Controls[i]).Enabled = false; } } } protected void Page_Load(object sender, EventArgs e) { SetRadioButton(Page); }
------解决方案--------------------
protected void Page_Load(object sender, EventArgs e)
{
SetRadioButton(this.Page);
}
public void SetRadioButton(Control obj)
{
for (int i = 0; i < obj.Controls.Count; i++)
{
if (obj.Controls[i].Controls.Count > 0)
SetRadioButton(obj.Controls[i]);
else
{
if (obj.Controls[i].GetType() == typeof(RadioButton))
((RadioButton)obj.Controls[i]).Enabled = false;
}
}
}