Empty text coming on transfer...

2 posts, 0 answers
  1. SK
    SK avatar
    14 posts
    Member since:
    Mar 2009

    Posted 31 Oct 2012 Link to this post

    I think I followed all the rules to transfer data between two listboxes but I am getting empty text when transferring from one list box to another...

    This is the aspx file
    <Telerik:RadListListBox id="lstAvailable" runat="server" allowtransfer="true" transfertoid="lstAllocated"
        width="350px" height="240px" autopostbackontransfer="true" selectionmode="Multiple">
        <HeaderTemplate>
            <div style="text-align: center; background-color: #EEE;">
                <asp:Label ID="lblAvailable" runat="server" Text="Available fields"></asp:Label
            </div>
        </HeaderTemplate>
        <ItemTemplate>
            <div style="width:auto">
                <%#Eval("Text") %>
            </div>
        </ItemTemplate>
    <Telerik:RadListListBox>
    <Telerik:RadListListBox id="lstAllocated" runat="server" selectionmode="Multiple" allowdelete="False"
        width="350px" height="240px" AllowReorder="True">
        <HeaderTemplate>
            <div style="text-align: center; background-color: #EEE;">
                <asp:Label ID="lblAllocated" runat="server" Text="Used fields"></asp:Label
            </div>
        </HeaderTemplate>
        <ItemTemplate>
            <div style="width:auto">
                <div style="float:left"><%#Eval("Text") %></div>
                <div style="float:Right">
                    <asp:CheckBox runat="server" ID="chkRequired" />
                </div>
            </div>
        </ItemTemplate>   
    </Telerik:RadListListBox>

    This is the cs file

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadFirstListBox();
            LoadSecondListBox();
        }
    }
     
    protected void LoadFirstListBox()
    {
        // Same as LoadSecondListBox (see below)
    }
     
    protected void LoadSecondListBox()
    {
            ListItemCollection lstAllocatedCollection = new ListItemCollection();
                ListItem allocatedItem = new ListItem(
                    "Test-1",
                    "22");
                allocatedItem.Attributes["Required"] = "true";
                lstAllocatedCollection.Add(allocatedItem);
                allocatedItem = new ListItem(
                    "Test-2",
                    "33");
                allocatedItem.Attributes["Required"] = "false";
                lstAllocatedCollection.Add(allocatedItem);
                lstAllocated.DataSource = lstAllocatedCollection;
                lstAllocated.DataTextField = "Text";
                lstAllocated.DataValueField = "Value";
                lstAllocated.DataBind();
    }
     
    void AllocatedListDataBound(object sender, Telerik.Web.UI.RadListBoxItemEventArgs e)
            {
                string checkedValue = (string) DataBinder.Eval(e.Item.DataItem, "Attributes['Required']");
                CheckBox checkBox = (CheckBox)e.Item.FindControl("chkRequired");
                checkBox.Checked = Convert.ToBoolean(checkedValue);
            }
     
    void lstAvailable_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e)
    {
                foreach(Telerik.Web.UI.RadListBoxItem item in e.Items)
                {
                    item.DataBind(); // Pretty much unnecessary because I am not really changing anything here
                }
    }

    After transferring an empty text is transferred... see attachment. What am I doing wrong?



  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 01 Nov 2012 Link to this post

    Hello SK,

    With the usage of the Eval in the markup, you rely on the DataItem in order to evaluate the text, but when a transferred is performed the DataItem do not persist. For that matter, I could suggest you to use the DataBinder in order to evaluate the Text of the transferred Item in a following manner :

    <%# DataBinder.Eval(Container, "Text") %>
     
    Here you could find detailed explanation on the matter.


    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top