Tuesday, February 1, 2011

Read only all textboxes


    protected void readonlyTextBoxes(Control parent)
    {
        foreach (Control c in parent.Controls)
        {
            if (c.GetType() == typeof(TextBox))
            {
                ((TextBox)(c)).ReadOnly = true;

            }
            else if (c.GetType() == typeof(DropDownList))
            {
                ((DropDownList)(c)).Enabled = false;

            }
            if (c.HasControls())
            {
                readonlyTextBoxes(c);
            }
        }

    }