This is a migrated thread and some comments may be shown as answers.

Transfer Templated Items

3 Answers 74 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 1
Jack asked on 22 Feb 2011, 01:15 AM
Hi,

Is it possible to transfer templated item between ListBoxes using the built in AllowTransfer feature..?  I have tried using client side and also with AutoPostBackOnTransfer="true".

I am using version 2010.3.1109.40 of Telerik.Web.UI.dll

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <telerik:RadScriptManager runat="server" />
        <telerik:RadListBox ID="rlbSource" runat="server" AllowTransfer="true" AutoPostBackOnTransfer="true"
            TransferToID="rlbDestination" Width="400" Height="200" OnTransferred="rlbSource_Transferred">
            <ItemTemplate>
                <table>
                    <tr>
                        <td><%# Eval("RoleName") %></td>
                        <td><%# Eval("UserName") %></td>
                        <td><%# Eval("FirstName") %></td>
                        <td><%# Eval("LastName") %></td>
                    </tr>
                </table>
            </ItemTemplate>
        </telerik:RadListBox>
            
        <telerik:RadListBox ID="rlbDestination" runat="server" Width="300" Height="200">
            <ItemTemplate>
                <table>
                    <tr>
                        <td><%# Eval("UserName") %></td>
                        <td><%# Eval("FirstName") %></td>
                        <td><%# Eval("LastName") %></td>
                    </tr>
                </table>
            </ItemTemplate>
        </telerik:RadListBox>
    </div>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using Telerik.Web.UI;
 
public partial class _Default : System.Web.UI.Page
{
    public class Employee
    {
        public string RoleName { get; set; }
        public string UserName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        rlbSource.DataSource = new List<Employee>
        {
            new Employee { RoleName = "Administrator", UserName = "Jack", FirstName = "Jack", LastName = "Pick" },
            new Employee { RoleName = "POS User", UserName = "Michael", FirstName = "Michael", LastName = "Black" },
            new Employee { RoleName = "Store Manager", UserName = "David", FirstName = "David", LastName = "Frontier" }
        };
        rlbSource.DataBind();
    }
 
    protected void rlbSource_Transferred(object sender, RadListBoxTransferredEventArgs e)
    {
        foreach (RadListBoxItem item in e.Items)
        {
            item.DataBind();
        }
    }
}


If it's possible to do entirely client side (without postback) that would be best, however I really just need it to work, so if it has to be done server side then that is fine.

Kind regards,
Jack

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Feb 2011, 08:51 AM
Hello Jack,

I have found this forum discussed similar scenario. Take a look at this.
Transfer for template in ListBox

Thanks,
Shinu.
0
David
Top achievements
Rank 1
answered on 24 Feb 2011, 01:34 AM
Hi Shinu,

Thank you for your response.  I had seen that thread already and took some tips from it but unfortunately it doesn't match my situation exactly.  The OP in that thread only needed two values in his template, which can be handled by binding to the DataTextField and DataValueField of the ListBox, as pointed out by the answerer.  In my situation I need 4 values in the left ListBox and 3 values in the right.  It doesn't work the same way.  I have created a support ticket with Telerik to see if they can come up with a solution.

Thanks again for your help.

Cheers,
Jack
0
Dimitar Terziev
Telerik team
answered on 24 Feb 2011, 05:19 PM
Hello David,

Since you are facing the issue that the values in the item template are more than two, so text and value are not enough, you should bind the rest values to a custom attributes. This is essential since when you transfer a particular item, you should also transfer the values from its template. So if these values are not bind to the lsitbox item, they will be lost. In your case you could easily bind RoleName as Text property and the rest as custom attributes. Then when you transfer this item you should subscribe to OnTransferred event and bind the item in the second listbox by explicitly invoking DataBind method.


Greetings,
Dimitar Terziev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
ListBox
Asked by
Jack
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
David
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or