Transfer Templated Items

4 posts, 0 answers
  1. Jack
    Jack avatar
    3 posts
    Member since:
    Feb 2011

    Posted 21 Feb 2011 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Feb 2011 Link to this post

    Hello Jack,

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

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. David
    David avatar
    1 posts
    Member since:
    Sep 2010

    Posted 23 Feb 2011 Link to this post

    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
  5. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 24 Feb 2011 Link to this post

    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!
Back to Top