This is the repeater:
<asp:Repeater ID="rptrReports" runat="server">
<ItemTemplate>
<div style="margin: 2">
<asp:Label ID="lblAccount" runat="server" Text='<%#Eval("Account").FullName%>' />
<asp:TextBox ID="txtDescription" runat="server" MaxLength="256" Text='<%#Eval("Description")%>'
ReadOnly="<%# Not Account.IsAdmin %>" BackColor="<%# If(Account.IsAdmin,Color.White, Color.Transparent) %>"
BorderStyle="<%# If(admin, BorderStyle.NotSet, BorderStyle.None) %>"
/>
<asp:TextBox ID="txtNote" runat="server" MaxLength="1024" Text='<%#Eval("Note")%>'
ReadOnly="<%# Not Account.IsAdmin %>" BackColor="<%# If(Account.IsAdmin,Color.White, Color.Transparent) %>"
BorderStyle="<%# If(admin, BorderStyle.NotSet, BorderStyle.None) %>" />
<!-- Here I have many more controls which I want to apply same rules !-->
</div>
</ItemTemplate>
</asp:Repeater>
I want to set these controls of the itemtemplate in code dynamically so the asp.net code shouldn't look so ugly:
Private Sub HandleTextBoxes()
Dim admin = Account.IsAdmin
For Each tb As TextBox In _
From c In rptrReports.Controls _
Where TypeOf c Is TextBox 'ItemTemplate doesn't expose the properties :(
With tb
.ReadOnly = Not admin
.BackColor = If(admin, Color.White, Color.Transparent)
.BorderStyle = If(admin, BorderStyle.NotSet, BorderStyle.None)
End With
Next
End Sub
In the other hand, I don't want to set it or each bound ItemTemplate separately, I want to set it thru to parent control (the repeater) itself.
Answers in C# will be welcomed too!