Is there a way to change several textbox's readonly attribute programatically in .net.
views:
469answers:
5
A:
Yes,
txt.Attributes["ReadOnly"] = "true";
Just use a loop for that :)
or you haven't that attribute in your controls tags.
you can either use that code
txt.Attributes.Add("ReadOnly","true");
Braveyard
2008-12-10 06:35:02
A:
You could load the names of the textboxes into a list and change them that way, or load the textbox objects into a list and change them.
foreach(TextBox txt in List) { txt.ReadOnly = true; }
fARcRY
2008-12-10 06:35:43
A:
Yes there is.
Add each textbox to an array, and then loop through the array changing the attributes.
For example:
Dim textBoxes() As TextBox = {TextBox1, TextBox2, TextBox3}
For Each item As TextBox In textBoxes
item.ReadOnly = True
Next
Matt Hanson
2008-12-10 07:03:37
+2
A:
Assuming your textboxes all begin with the same prefix and exist in the page controls collection:
string commonTextBoxPrefix = "txt";
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(TextBox) &&
c.Name.StartsWith(commonTextBoxPrefix))
{
((TextBox)c).ReadOnly = True;
}
}
This will not recurse the entire control hierarchy though :)
Neil
2008-12-10 07:48:28