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

Can't get transfer working...

5 Answers 94 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Iron
Paul asked on 17 Sep 2012, 06:56 PM
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();
 
            }
        }
 
       
 
        
 
        
    }
}

5 Answers, 1 is accepted

Sort by
0
Accepted
Nencho
Telerik team
answered on 20 Sep 2012, 03:04 PM
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.
0
Paul
Top achievements
Rank 1
Iron
answered on 20 Sep 2012, 03:34 PM
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!

0
Nencho
Telerik team
answered on 21 Sep 2012, 01:37 PM
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.
0
Paul
Top achievements
Rank 1
Iron
answered on 21 Sep 2012, 02:25 PM
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!
0
Paul
Top achievements
Rank 1
Iron
answered on 21 Sep 2012, 05:05 PM
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 ;) ).
Tags
ListBox
Asked by
Paul
Top achievements
Rank 1
Iron
Answers by
Nencho
Telerik team
Paul
Top achievements
Rank 1
Iron
Share this question
or