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

作者:袖梨 2022-06-25
 代码如下 复制代码

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;

}

相关文章

精彩推荐