How to dynamically change databound label's dataitem in asp.net Repeater
Posted on 2016-08-27
I have a databound repeater control in an asp.net 4 website.
Here's some of the markup:
<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>
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.