Programmatically Transfer RadListBoxItem

3 posts, 1 answers
  1. Garrett
    Garrett avatar
    23 posts
    Member since:
    Sep 2012

    Posted 21 Mar 2011 Link to this post

    Hello,

    I am currently trying to transfer RadListBox items from one control to another using programming code (Csharp).

    Here is my setup:

    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div>
        <telerik:RadListBox ID="RadListBox1" OnLoad="RadListBox1_OnLoad" AllowTransfer="true" Height="400px" Width="300px" DataSourceID="SqlDataSource1" DataValueField="AmRepID" DataTextField="RepInfo" AllowTransferOnDoubleClick="true"
                            SelectionMode="Multiple" TransferMode="Move"
                            TransferToID="RepBoxSelected" runat="server">
        </telerik:RadListBox>
     
        <telerik:RadListBox ID="RepBoxSelected" Height="400px" Width="300px"
                            TransferToID="RadListBox1" runat="server">
        </telerik:RadListBox>
     
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionString %>"
            SelectCommand="SELECT Statement Here"></asp:SqlDataSource>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Text.RegularExpressions;
    using Telerik.Web.UI;
     
    public partial class reports_MassMail : System.Web.UI.Page
    {
        protected void RadListBox1_OnLoad(object sender, EventArgs e)
        {
     
        }
        protected void Page_Load(object sender, EventArgs e)
        {
                RadListBoxItem founditem = RadListBox1.FindItemByText("CAMPUS - <Rep Name>");
                RadListBox1.Transfer(founditem, RadListBox1, RepBoxSelected);
        }
    }

    (Missing info in SqlDataSource was intentional).

    Every time I run this, I get "Object Reference not set to an instance of an object." on the RadListBoxItem founditem line in the CSharp code.

    What am I doing wrong?
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Mar 2011 Link to this post

    Hello Garrett,

    The pageLoad event is too early in rendering the RadListBoxItem and hence you can try the same in the PreRender event of the RadListBox.
    C#:

    protected void RadListBox1_PreRender(object sender, EventArgs e)
      {
          RadListBoxItem founditem = RadListBox1.FindItemByText("CAMPUS - <Rep Name>");
          RadListBox1.Transfer(founditem, RadListBox1, RepBoxSelected);
      }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Garrett
    Garrett avatar
    23 posts
    Member since:
    Sep 2012

    Posted 22 Mar 2011 Link to this post

    Ugh. I've been staring at code too long. Thanks for your help! :)
Back to Top