遍历指定的控件类型 设置为只读

protected void TurnControlsReadOnly()
{
    foreach (Control obj in form1.Controls)
    {
        if (obj is TextBox)
        {
            //obj.Attributes.Add("readonly", "true");
            ((TextBox)obj).ReadOnly = true;
        }
    }
 
 
    foreach (Control obja in form1.Controls)
    {
        if (obja is DropDownList)
        {
            ((DropDownList)obja).Enabled = false;
        }
    }
 
    foreach (Control objb in form1.Controls)
    {
        if (objb is Button)
        {
            ((Button)objb).Visible = false;
            ((Button)objb).Enabled = false;
 
        }
    }
 
    foreach (Control obja in form1.Controls)
    {
        if (obja is RadioButtonList)
        {
            ((RadioButtonList)obja).Enabled = false;
        }
    }
 
    dropSort.Enabled = false;
    //btnUPloadIma.Visible = false;
    ddlCategory.Enabled = true;
    btnSaveCategory.Visible = true;
    btnSaveCategory.Enabled = true;
    txtOtherCategory.ReadOnly = false;
    txtSortOther.ReadOnly = true;
 
    for (int i = 0; i < dlstProductImage.Items.Count; i++)
    {
        dlstProductImage.Items[i].FindControl("lbtnDelete").Visible = false;
    }
    fldBuyInfoImage.Visible = false;
}

你可能感兴趣的:(遍历)