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

Empty text coming on transfer...

1 Answer 44 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
SK
Top achievements
Rank 1
SK asked on 31 Oct 2012, 05:47 PM
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?



1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 01 Nov 2012, 04:07 PM
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.
Tags
ListBox
Asked by
SK
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or