New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Transfer RadListBoxItems with ItemTemplates
Updated over 6 months ago
HOW-TO
Transfer RadListBoxItems with ItemTemplates, evaluated from the datasource.
SOLUTION
When the values from the attributes(assigned from the DataItem) are used to be evaluated in the ItemTemplate in the following manner,
ASP.NET
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "Attributes[\"ContactName\"]")%>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "Attributes[\"City\"]")%>'></asp:Label>
</ItemTemplate>
the DataBind() method should be explicitly called for each RadListBoxItem, when a transfer operation is performed. This is needed, because the DataItem is nullified, once the datasource is bound to the SourceListBox. The appropriate event-handler for implementing the above is the OnTransferred event handler:
C#
protected void SourceListBox_Transferred(object sender, RadListBoxTransferredEventArgs e)
{
foreach (RadListBoxItem item in e.Items)
{
item.DataBind();
}
}A sample project that demonstrates the approach can be found attached here