ItemTemplate transfer empty

4 posts, 0 answers
  1. Mikael
    Mikael avatar
    11 posts
    Member since:
    Mar 2013

    Posted 25 Mar 2014 Link to this post

    Hello,

    I want to transfer an item in a listbox to another listbox like in this example : http://demos.telerik.com/aspnet-ajax/listbox/examples/functionality/templates/defaultcs.aspx
    My problem is when I transfered an item in the second lisbox the item is empty (see the attached file).

    <telerik:RadListBox ID="RLB_References" runat="server" Width="360px" TransferToID="RLB_SelectedReference"
        AutoPostBackOnTransfer="True" AllowTransfer="True" OnTransferred="RLB_References_Transferred">
        <HeaderTemplate>
            <table>
                <tr>
                    <td width="80px">Titre</td>
                    <td width="80px">Référence</td>
                    <td width="80px">Taille</td>
                    <td width="80px">Coloris</td>
                </tr>
            </table
        </HeaderTemplate>
        <ItemTemplate>
            <table>
                <tr>
                    <td width="90px">
                        <%# DataBinder.Eval(Container.DataItem, "Titre") %>
                    </td>
                    <td width="90px">
                        <%# DataBinder.Eval(Container.DataItem, "Reference") %>
                    </td>
                    <td width="90px">
                        <%# DataBinder.Eval(Container.DataItem, "Taille") %>
                    </td>
                    <td width="90px">
                        <%# DataBinder.Eval(Container.DataItem, "Coloris") %>
                    </td>
                </tr>
            </table>  
        </ItemTemplate>
    </telerik:RadListBox>
     
    <telerik:RadListBox ID="RLB_SelectedReference" runat="server" Width="400px">
         <HeaderTemplate>
            <table>
                <tr>
                    <td width="80px">Titre</td>
                    <td width="80px">Référence</td>
                    <td width="80px">Taille</td>
                    <td width="80px">Coloris</td>
                    <td width="80px">Quantité</td>
                </tr>
            </table
        </HeaderTemplate>
        <ItemTemplate>
            <table>
                <tr>
                    <td width="80px">
                        <%# DataBinder.Eval(Container.DataItem, "Titre") %>
                    </td>
                    <td width="80px">
                        <%# DataBinder.Eval(Container.DataItem, "Reference") %>
                    </td>
                    <td width="80px">
                        <%# DataBinder.Eval(Container.DataItem, "Taille") %>
                    </td>
                    <td width="80px">
                        <%# DataBinder.Eval(Container.DataItem, "Coloris") %>
                    </td>
                    <td width="80px">
                        <telerik:RadNumericTextBox runat="server" ID="QuantityTextBox" Width="50px" MinValue="1"
                            ShowSpinButtons="true" Value="1" NumberFormat-DecimalDigits="0">
                        </telerik:RadNumericTextBox>
                    </td>
                </tr>
            </table>  
        </ItemTemplate>
    </telerik:RadListBox>

    private string GetArticleTitle(int nodeId)
        {
            return "title";
        }
     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                List<tbl_references> references = null;
                using (ReferenceContainer context = new ReferenceContainer())
                {
                    references = context.tbl_references.ToList();
                }
                var datasource = from r in references
                                 let reference = r.Reference
                                 let taille = r.Taille
                                 let coloris = r.Coloris
                                 let titre = GetArticleTitle(r.ArticleNodeId)
                                 select new
                                 {
                                     Reference = reference,
                                     Taille = taille,
                                     Coloris = coloris,
                                     Titre = titre
                                 };
                RLB_References.DataSource = datasource;
                RLB_References.DataBind();
            }
        }
     
        protected void RLB_References_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e)
        {
            foreach (RadListBoxItem item in e.Items)
            {
                item.DataBind();
            }
        }

    Have you a solution ?

    Thanks.
  2. Mikael
    Mikael avatar
    11 posts
    Member since:
    Mar 2013

    Posted 25 Mar 2014 Link to this post

    I put a breakpoint in the RLB_References_Transferred method and I noticed that :
     - item.Value = { Reference = 1236, Taille = Taille S, Coloris = Rouge, Titre = AUDI TT }
     - item.DataItem = null
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Mar 2014 in reply to Mikael Link to this post

    Hi Mikael

    In your sample code, you are binding directly to the DataItem property of the item. This property is useful when the ListBox is bound to a datasource. So when you transfer the item to the second ListBox, since it is not bound , this property is null. If you want to bind to properties from the DataItem, you should use the ItemDataBound event to map them to properties of the item itself. The best way to store arbitrary properties is to use the item's AttributeCollection. Please have a look into this help documentation for further help.

    Thanks,
    Princy.
  5. Mikael
    Mikael avatar
    11 posts
    Member since:
    Mar 2013

    Posted 26 Mar 2014 Link to this post

    Thank you Princy.
    It works great now.
Back to Top