David Rudlin
asked on
How to dynamically change databound label's dataitem in asp.net Repeater
I have a databound repeater control in an asp.net 4 website.
Here's some of the markup:
<ItemTemplate>
<tr>
<td>
<asp:Label ID="txtSurname" runat="server" CssClass="RepeaterLabel2"
Enabled="True" Text='<%# DataBinder.Eval(Container. DataItem, "Surname") %>'
Width="70px" ToolTip='<%# DataBinder.Eval(Container. DataItem, "Surname") %>'></asp:Label>
</td>
I need to change the DataItem for the "txtSurname" label dynamically based on user preference so that it might be bound to the "LegalSurname" dataitem if the user requires it. So user checks the "Show legal surname" option on the webpage and the repeater then refreshes to show legal surname rather than preferred surname - and vice versa.
Can anybody suggest how that might be done?
Many thanks in advance.
Here's some of the markup:
<ItemTemplate>
<tr>
<td>
<asp:Label ID="txtSurname" runat="server" CssClass="RepeaterLabel2"
Enabled="True" Text='<%# DataBinder.Eval(Container.
Width="70px" ToolTip='<%# DataBinder.Eval(Container.
</td>
I need to change the DataItem for the "txtSurname" label dynamically based on user preference so that it might be bound to the "LegalSurname" dataitem if the user requires it. So user checks the "Show legal surname" option on the webpage and the repeater then refreshes to show legal surname rather than preferred surname - and vice versa.
Can anybody suggest how that might be done?
Many thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was looking for something far too complicated!
Actually we have it all inside an Update panel so the refreshing is fine.
Here's the actual code I finally used (we're working in VB):
<td>
<asp:Label ID="txtSurname" runat="server" CssClass="RepeaterLabel2"
Enabled="True" Text='<%# If(chkPreferredNames.Check
Width="70px" ToolTip='<%# DataBinder.Eval(Container.
</td>