![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
protected void SetReadOnly(Control ctrl)
{
if (!ctrl.HasControls())
{
if (ctrl is TextBox)
{
TextBox tb = (TextBox)ctrl;
tb.Enabled = false;
}
if (ctrl is DropDownList)
{
DropDownList ddl = (DropDownList)ctrl;
ddl.Enabled = false;
}
}
else
{
int i = 0;
while (i < ctrl.Controls.Count)
{
SetReadOnly(ctrl.Controls[i]);
i++;
}
}
}
{
if (!ctrl.HasControls())
{
if (ctrl is TextBox)
{
TextBox tb = (TextBox)ctrl;
tb.Enabled = false;
}
if (ctrl is DropDownList)
{
DropDownList ddl = (DropDownList)ctrl;
ddl.Enabled = false;
}
}
else
{
int i = 0;
while (i < ctrl.Controls.Count)
{
SetReadOnly(ctrl.Controls[i]);
i++;
}
}
}