Can't get transfer working...

6 posts, 1 answers
  1. Paul
    Paul avatar
    27 posts
    Member since:
    Feb 2012

    Posted 17 Sep 2012 Link to this post

    Sorry for what is likely a repeat of past threads, but in spite of looking through the forum, I can't seem to get this to work.  I have 2 listboxes, the "source" listbox is databound to a LINQ query and I want to be able to transfer items to a second listbox.  In spite of (I think) carefully following the past examples, I can't get it working.  The "transfered" event on the source doesn't appear to be firing at all, and when I attempt to do a transfer even of a single item, both listboxes wind up empty.  I'd be very veryyyyyyy grateful for any guidance.  My listboxes are defined as such:
    <div class="left">
            <telerik:RadListBox ID="ticketListbox" runat="server"
             ItemPlaceholderID="TicketContainer"
                EnableViewState="False"  Font-Names=""Helvetica 65 Medium",Arial,sans-serif"
                Font-Size="Medium" ForeColor="#C36029" Width="275px" AllowTransfer="True"
                  TransferToID="splitListbox" AutoPostBackOnTransfer="True"
                  SelectionMode="Multiple" ontransferred="ticketListbox_Transferred">
                 
    <ButtonSettings TransferButtons="All"></ButtonSettings>
                 
                <ItemTemplate>
           <table style="font-family: Arial, Helvetica, sans-serif;  font-size: medium; color: #C36029">
           <td>
            <%#Eval("Quantity")%>
           </td>
           <td>
            <%#Eval("Name")%>
           </td>
            <td>
            <%#Eval("Price","{0:c}")%>
           </td>   
           </table>              
           </ItemTemplate>      
            </telerik:RadListBox>
            </div>
     
            <div class="centerElements">
              <telerik:RadListBox ID="splitListbox" runat="server"
                ItemPlaceholderID="splitContainer"
                EnableViewState="False"  Font-Names=""Helvetica 65 Medium",Arial,sans-serif"
                Font-Size="Medium" ForeColor="#C36029" Width="275px" AllowTransfer="False"
                     >
              
    <ButtonSettings TransferButtons="All"></ButtonSettings>
              
                   <ItemTemplate>
           <table style="font-family: Arial, Helvetica, sans-serif;  font-size: medium; color: #C36029">
           <td>
            <%#Eval("Quantity")%>
           </td>
           <td>
            <%#Eval("Name")%>
           </td>
            <td>
            <%#Eval("Price","{0:c}")%>
           </td>   
           </table>              
           </ItemTemplate>          
              </telerik:RadListBox>
              </div>

    And my code behind is as follows:
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!User.Identity.IsAuthenticated)
                {
                    Response.Redirect("http://localhost:64501/LogOn.aspx");
     
                }
                if (!Page.IsPostBack)
                {
                    ticketListbox.DataBind();
                    splitListbox.DataBind();
                }
     
                
            }
     
            protected void Button1_Click(object sender, EventArgs e)
            {
                CaffeBravoContext tc = new CaffeBravoContext();
                int tableNo = System.Convert.ToInt16(tableTextbox.Text);
                var table = from t in tc.Tickets
                            where (t.Table==tableNo)&&
                            (t.Closed_==false)                       
                            select t;
     
                if (table.Count()==0)
                {
                    statusLbl.Text="There is no open ticket for that table!";
                }
                else
                {
                    var tickets = from d in tc.Ticket_Details
                                  where d.Ticket_ == table.FirstOrDefault().Ticket_Number
                                  select d;
                   
     
                    ticketListbox.DataSource = tickets.ToList();               
                    ticketListbox.DataBind();
                }
            }
     
            protected void ticketListbox_Transferred(object sender, RadListBoxTransferredEventArgs e)
            {
                foreach (RadListBoxItem item in e.Items)
                {
     
                    item.DataBind();
     
                }
            }
     
           
     
            
     
            
        }
    }
  2. Answer
    Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 20 Sep 2012 Link to this post

    Hello Paul,

    In order to enable the transfer feature, the EnableViewState property should be set to True. Since you use a datasource to populate the ticketListBox, when transferring an Item to the second RadLisBox you should use the ItemDataBound event handler in order to add the desired attributes (QuantityName, Price). In addition, you should set the AllowTransferDuplicates property to true, since you do not assign a DataTextField value. Here is an example of the implementation, which is suitable for your scenario.

    Markup:
    <telerik:RadListBox ID="ticketListbox" runat="server" _ItemPlaceholderID="TicketContainer"
            Height="275px" EnableViewState="true" Font-Size="Medium" ForeColor="#C36029" OnItemDataBound="ticketListbox_ItemDataBound"
            Width="275px" AllowTransferDuplicates="true" AllowTransfer="True" TransferToID="splitListbox"
            AutoPostBackOnTransfer="True" SelectionMode="Multiple" OnTransferred="ticketListbox_Transferred" >
            <ButtonSettings TransferButtons="All"></ButtonSettings>
            <ItemTemplate>
                <table style="font-family: Arial, Helvetica, sans-serif; font-size: medium; color: #C36029">
                    <td>
                        <%# DataBinder.Eval(Container, "Attributes['Quantity']")%>
                    </td>
                    <td>
                        <%# DataBinder.Eval(Container, "Attributes['Name']")%>
                    </td>
                    <td>
                        <%# DataBinder.Eval(Container, "Attributes['Price']")%>
                    </td>
                </table>
            </ItemTemplate>
        </telerik:RadListBox>
    <telerik:RadListBox ID="splitListbox" runat="server" _ItemPlaceholderID="splitContainer" OnItemDataBound="splitListbox_ItemDataBound"
            Height="275px" EnableViewState="true" Font-Size="Medium" ForeColor="#C36029"
            Width="275px">
            <ButtonSettings TransferButtons="All"></ButtonSettings>
            <ItemTemplate>
                <table style="font-family: Arial, Helvetica, sans-serif; font-size: medium; color: #C36029">
                    <td>
                        <%# DataBinder.Eval(Container, "Attributes['Quantity']")%>
                    </td>
                    <td>
                        <%# DataBinder.Eval(Container, "Attributes['Name']")%>
                    </td>
                    <td>
                        <%# DataBinder.Eval(Container, "Attributes['Price']")%>
                    </td>
                </table>
            </ItemTemplate>
        </telerik:RadListBox>

    Code behind:
    protected void splitListbox_ItemDataBound(object sender, RadListBoxItemEventArgs e)
        {
            e.Item.Attributes.Add("Quantity", (e.Item.DataItem as DataRowView)["Quantity"].ToString());
            e.Item.Attributes.Add("Name", (e.Item.DataItem as DataRowView)["Name"].ToString());
            e.Item.Attributes.Add("TrackID", (e.Item.DataItem as DataRowView)["TrackID"].ToString());
            e.Item.DataBind();
        }
     
        protected void ticketListbox_ItemDataBound(object sender, RadListBoxItemEventArgs e)
        {
            e.Item.Attributes.Add("Quantity", (e.Item.DataItem as DataRowView)["Quantity"].ToString());
            e.Item.Attributes.Add("Name", (e.Item.DataItem as DataRowView)["Name"].ToString());
            e.Item.Attributes.Add("Price", (e.Item.DataItem as DataRowView)["Price"].ToString());
            e.Item.DataBind();
        }
     protected void ticketListbox_Transferred(object sender, RadListBoxTransferredEventArgs e)
        {
            foreach (RadListBoxItem item in e.Items)
            {
                item.DataBind();
            }
        }


    All the best,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul
    Paul avatar
    27 posts
    Member since:
    Feb 2012

    Posted 20 Sep 2012 Link to this post

    Nencho,

    Thank you very very much for all the time you took in your reply.  I've been beating my head against this for almost two days and "we" are so close I can taste it ;)

    But now I'm getting a null reference exception that doesn't make any sense... maybe I'm just tired from this part of the project (actually I know I am).  Any suggestion?  I'm sure it's obvious but I'm getting fried...

    Line 79: protected void ticketListBox_ItemDataBound(object sender, RadListBoxItemEventArgs e) 
    Line 80: {
    Line 81: e.Item.Attributes.Add("Quantity", (e.Item.DataItem as DataRowView)["Quantity"].ToString());
    Line 82: e.Item.Attributes.Add("Name", (e.Item.DataItem as DataRowView)["Name"].ToString());
    Line 83: e.Item.Attributes.Add("Price", (e.Item.DataItem as DataRowView)["Price"].ToString());


    Again... I'm very grateful for all your help!

  5. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 21 Sep 2012 Link to this post

    Hello Paul,

    Since I could not reproduce the problem with your database environment, I am sending you a video, in order to demonstrate you how you could overcome the described exception. I am using a declarative datasource at my end. Upon the ItemDataBound event handler, you could check of the e.Item.DataItem, and cast it to the corresponding type. Please let me know if you manage to deal with the problem.


    Regards,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Paul
    Paul avatar
    27 posts
    Member since:
    Feb 2012

    Posted 21 Sep 2012 Link to this post

    Thanks again, sincerely for all your help Nencho... I'm sorry to say that I seem to be getting nowhere fast :S  I don't see any differences between your solution and what I have so why your's works and mine doesn't escapes me.  I'm afraid I don't quite understand your last suggestion...

    Thanks again for all your efforts!
  7. Paul
    Paul avatar
    27 posts
    Member since:
    Feb 2012

    Posted 21 Sep 2012 Link to this post

    Nencho...

    Just to avoid wasting your time, I believe I have it working.  All I did was change from the EF datasource that I had set, and wrote a SQL query.  I saw that that was the only difference between your app and mine.  I have no idea really what EF does in terms of wrapping but that somehow was at the heart of the issue. 

    Once again... thank you... I'm very very grateful for all your time.  I'll let you know if I run into any further issues... (praying not ;) ).
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017