Transfer for template in ListBox

9 posts, 0 answers
  1. Taraman
    Taraman avatar
    17 posts
    Member since:
    Aug 2010

    Posted 05 Dec 2010 Link to this post

    Dear telerik,
    I have create a listbox with template item, the problem when trying to transfer items it transfered but it appears empty

    please help

    ASPX:
    <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel3">
        <telerik:RadListBox ID="RadListBox5" runat="server" Height="150px" Width="215px" SelectionMode="Single"
            AutoPostBackOnTransfer="true" AllowTransfer="true"
            TransferToID="RadListBox6" OnTransferred="RadListBox5_Transferred">
            <ButtonSettings ShowTransferAll="false" VerticalAlign="Middle" />
            <ItemTemplate>
                <table cellpadding="1" cellspacing="0" border="0">
                    <tr>
                        <td><b><%# Eval("Title") %></b></td>
                        <td> [Price:</td>
                        <td><%# Convert.ToInt32(Eval("Price")).ToString("C0")%>]</td>
                    </tr>
                </table>
            </ItemTemplate>
        </telerik:RadListBox>
        <telerik:RadListBox ID="RadListBox6" runat="server" Height="150px" Width="200px" SelectionMode="Single">
            <ItemTemplate>
                <table cellpadding="1" cellspacing="0" border="0">
                    <tr>
                        <td><b><%# Eval("Title") %></b></td>
                        <td> [Price:</td>
                        <td><%# Convert.ToInt32(Eval("Price")).ToString("C0")%>]</td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            Quantity:
                            <telerik:RadNumericTextBox runat="server" ID="QuantityTextBox" Width="80px" MinValue="1" MaxValue="10" ShowSpinButtons="true" Value="1" NumberFormat-DecimalDigits="0" />
                            <asp:RequiredFieldValidator ID="RequiredQuantityTextBox" ControlToValidate="QuantityTextBox" runat="server" ErrorMessage="*">*</asp:RequiredFieldValidator>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </telerik:RadListBox>
    </telerik:RadAjaxPanel>

    CS:
          protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                RadListBox5_Load();
                RadListBox6_Load();
            }
        }
     
          public class Spinning
        {
            public string Title { get; set; }
            public double Price { get; set; }
            public int Quantity { get; set; }
        }
     
        void RadListBox5_Load()
        {
            List<Spinning> SpinningList = new List<Spinning>
            {
                new Spinning { Title = "Spinning Reel 1", Price = 100, Quantity = 1 },
                new Spinning { Title = "Spinning Reel 2", Price = 200, Quantity = 2 },
                new Spinning { Title = "Spinning Reel 3", Price = 300, Quantity = 3 }
            };
     
            RadListBox5.DataSource = SpinningList;
            RadListBox5.DataBind();
        }
     
        void RadListBox6_Load()
        {
            List<Spinning> SpinningList = new List<Spinning>
            {
                new Spinning { Title = "Spinning Reel 4", Price = 400, Quantity = 4 },
                new Spinning { Title = "Spinning Reel 5", Price = 500, Quantity = 5 },
                new Spinning { Title = "Spinning Reel 6", Price = 600, Quantity = 6 }
            };
     
            RadListBox6.DataSource = SpinningList;
            RadListBox6.DataBind();
        }
     
        protected void RadListBox5_Transferred(object sender, RadListBoxTransferredEventArgs e)
        {
            foreach (RadListBoxItem item in e.Items)
            {
                item.DataBind();
            }
        }

  2. Alan
    Alan avatar
    107 posts
    Member since:
    Oct 2010

    Posted 07 Dec 2010 Link to this post

    I have the exact same problem.

    When I load the items from database the template works, but when I transfer from another listbox it does not.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 08 Dec 2010 Link to this post

    Hello Daryl,

    The problem was that the data item was not  tranferred . We've made some changes in order to work properly.

    Kind regards,
    Dimitar Terziev
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  5. Alan
    Alan avatar
    107 posts
    Member since:
    Oct 2010

    Posted 09 Dec 2010 Link to this post

    I correct myself, the problem is the same, on the other hand my code is different.

    ASPX:
    <tr>
        <td valign="top">
            Company
        </td>
        <td>
            <telerik:RadListBox ID="rlbCompanies" runat="server" AllowTransfer="true" TransferToID="rlbCompaniesSelected"
                Height="150px" Width="185px" AllowTransferOnDoubleClick="true" EnableDragAndDrop="true"
                Skin="Windows7" AutoPostBackOnTransfer="True" Sort="Descending"
                SortCaseSensitive="False">
            </telerik:RadListBox>
        </td>
        <td colspan="2">
            <telerik:RadListBox ID="rlbCompaniesSelected" runat="server" EmptyMessage="Drag Company Here"
                Height="150px" Width="153px" Skin="Windows7" CssClass="listRight" EnableDragAndDrop="true"
                OnInserted="rlbCompaniesSelected_Inserted" AutoPostBackOnTransfer="True" OnDeleted="rlbCompaniesSelected_Deleted"
                AllowTransfer="false"
                OnClientSelectedIndexChanged="companySelected"
                onclienttransferring="companyTransferring">
                <ItemTemplate>
                    <%# DataBinder.Eval(Container, "Text") %>
                   <span class="inactiveItem"><%# DataBinder.Eval(Container, "Attributes['AdditionalText']") %></span>
                </ItemTemplate>
            </telerik:RadListBox>
        </td>
    </tr>

    C#

    This works (when loading)

    foreach (UserCompany company in user.UserCompanies)
    {
        // Find company and transfer.
        List<RadListBoxItem> companies = rlbCompanies.Items.Where(b => b.Value.Equals(company.CompanyID.ToString())).ToList<RadListBoxItem>();
         
        // If inactive, add to additional text.
        foreach (RadListBoxItem radItem in companies)
        {
            rlbCompanies.Transfer(radItem, rlbCompanies, rlbCompaniesSelected);
             
            if (company.Inactive)
            {
                radItem.AllowDrag = false;
                radItem.Attributes["AdditionalText"] = " (Inactive)";
            }
        }
    }
     
    rlbCompaniesSelected.DataBind();

    On the other hand, transferring from one to another manually (from UI) doesn't work. I get a blank entry.

    Thanks,
    Daryl



  6. Alan
    Alan avatar
    107 posts
    Member since:
    Oct 2010

    Posted 09 Dec 2010 Link to this post

    Created it from scratch, and it's now working - not sure what the problem was. Sorry if I wasted any of your time.

    Thanks,
    Daryl
  7. Taraman
    Taraman avatar
    17 posts
    Member since:
    Aug 2010

    Posted 13 Dec 2010 Link to this post

    Dear telerik,
    Thanks for help, it is now working.
    I have another issue, I need to load the textBox inside the list box with data
    I have the following object:
    List<Spinning> SpinningList = new List<Spinning>
            {
                new Spinning { Title = "Spinning Reel 4", Price = 400, Quantity = 4 },
                new Spinning { Title = "Spinning Reel 5", Price = 500, Quantity = 5 },
                new Spinning { Title = "Spinning Reel 6", Price = 600, Quantity = 6 }
            };

    currently we can load "Title" and "Price" using the following code
    <telerik:RadListBox ID="RadListBox7" runat="server" Height="100px" Width="215px"
                            SelectionMode="Single" AutoPostBackOnTransfer="true" AllowTransfer="true"
                            TransferToID="RadListBox8" OnTransferred="RadListBox7_Transferred"
                            DataTextField="Title" DataValueField="Price">
                            <ButtonSettings ShowTransferAll="false" VerticalAlign="Middle" />
                            <ItemTemplate>
                                <table cellpadding="1" cellspacing="0" border="0">
                                    <tr>
                                        <td>
                                            <b>
                                                <%# DataBinder.Eval(Container, "Text") %></b>
                                        </td>
                                        <td>
                                            [Price:
                                        </td>
                                        <td>
                                            <%# Convert.ToInt32(DataBinder.Eval(Container, "Value")).ToString("C0")%>]
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </telerik:RadListBox>
    but when try the following :
    <telerik:RadListBox ID="RadListBox8" runat="server" Height="100px" Width="200px"
                            SelectionMode="Single" DataTextField="Title" DataValueField="Price">
                            <ItemTemplate>
                                <table cellpadding="1" cellspacing="0" border="0">
                                    <tr>
                                        <td>
                                            <b>
                                                <%# DataBinder.Eval(Container, "Text")%></b>
                                        </td>
                                        <td>
                                            [Price:
                                        </td>
                                        <td>
                                            <%# Convert.ToInt32(DataBinder.Eval(Container, "Value")).ToString("C0")%>]
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="3">
                                            Quantity:
                                            <telerik:RadNumericTextBox runat="server" ID="QuantityTextBox" Width="80px" MinValue="1"
                                                MaxValue="10" ShowSpinButtons="true" Value='<%# DataBinder.Eval(Container, "Quantity") %>' NumberFormat-DecimalDigits="0"  />
                                            <asp:RequiredFieldValidator ID="RequiredQuantityTextBox" ControlToValidate="QuantityTextBox"
                                                runat="server" ErrorMessage="*">*</asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </telerik:RadListBox>

    it give me the following error:

    DataBinding: 'Telerik.Web.UI.RadListBoxItem' does not contain a property with the name 'Quantity'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: DataBinding: 'Telerik.Web.UI.RadListBoxItem' does not contain a property with the name 'Quantity'.

    Source Error:

    Line 198:									<td colspan="3">
    Line 199:										Quantity:
    Line 200:										<telerik:RadNumericTextBox runat="server" ID="QuantityTextBox" Width="80px" MinValue="1"
    Line 201:											MaxValue="10" ShowSpinButtons="true" Value='<%# DataBinder.Eval(Container, "Quantity") %>' NumberFormat-DecimalDigits="0"  />
    Line 202:										<asp:RequiredFieldValidator ID="RequiredQuantityTextBox" ControlToValidate="QuantityTextBox"

    Source File: d:\01- AlexProSoft\Projects\LearnDotNet\LearnDotNet.Solution\LearnDotNet\LearnTelerik\ListBox\ListBox_05_Template.aspx    Line: 200


    Please help

    thanks,
    Mohamed Taraman





  8. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 15 Dec 2010 Link to this post

    Hello Taraman,

    You could make a custom attribute Quantity in your ListBox in order to bind data to it  or you could change
    <%# DataBinder.Eval(Container, "Quantity") %>    with
     <%# DataBinder.Eval(Container.DataItem, "Quantity") %>


    All the best,
    Dimitar Terziev
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  9. Taraman
    Taraman avatar
    17 posts
    Member since:
    Aug 2010

    Posted 15 Dec 2010 Link to this post

    Dear Telerik,

    it is working, but can I set the text box with data while transfering in code behind

    thanks,
    Taraman
  10. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 20 Dec 2010 Link to this post

    Hi Taraman,

    You could use the FindControl method of the RadListBoxItem object. This way you get access to the controls in a template. Here is a small example:

    RadTextBox textbox = (RadTextBox) item.FindControl("RadTextBox1");
    textbox.Text = "Hello";


    Best wishes,
    Dimitar Terziev
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017