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

Programmatically Transfer RadListBoxItem

2 Answers 226 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Garrett
Top achievements
Rank 1
Garrett asked on 21 Mar 2011, 04:41 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 22 Mar 2011, 08:24 AM
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.
0
Garrett
Top achievements
Rank 1
answered on 22 Mar 2011, 03:35 PM
Ugh. I've been staring at code too long. Thanks for your help! :)
Tags
ListBox
Asked by
Garrett
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Garrett
Top achievements
Rank 1
Share this question
or