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

transfer items between 2 radlistbox

15 Answers 444 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Troika
Top achievements
Rank 1
Troika asked on 24 Sep 2013, 09:12 AM
i have 2 listbox wich are updated when user select an item from radgrid, so if radgrid item change radlistbox are updated.

but i have the arrows on the listbox to allow user transfer from one to another radlistbox and when user do that it must run a db update command.

the problem is that i cant get a way to fetch wich iem is selected from radlistbox by user. i try with items count but i get always zero

  protected void RadListBox1_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RadListBox1.Visible = false;
                RadListBox2.Visible = false;
                Label1.Visible = false;
                Label2.Visible = false;
            }
            else
            {
                RadListBox1.Visible = true;
                RadListBox2.Visible = true;
                Label1.Visible = true;
                Label2.Visible = true;
                RadListBox1.ClientIDMode = ClientIDMode.Static;
                RadListBox2.ClientIDMode = ClientIDMode.Static;
 
            }
 
 
 {
             
 
            if (e.Items.Count > 1 && e.SourceListBox.ClientID == "RadListBox1")
            {
                
                lblTransfer.Text = "Transfer All to right";
               command //BLL.Patrocinadores.Adicionar1PatrocinadorAoAtleta(id_atleta, id_patrocinador);
 
Updatelistbox();
 
 
            }
            else if (e.Items.Count == 1 && e.SourceListBox.ClientID == "RadListBox1")
            {
                lblTransfer.Text = "Transfer one Item to right";
            }
            else if (e.Items.Count > 1 && e.SourceListBox.ClientID == "RadListBox2")
            {
                lblTransfer.Text = "Transfer All to left";
            }
            else if (e.Items.Count == 1 && e.SourceListBox.ClientID == "RadListBox2")
            {
                lblTransfer.Text = "Transfer one Item to left";
            }
        }

15 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Sep 2013, 09:24 AM
Hi Troika,

Please take a look into the following code snippet that I tried to transfer the items from one RadListBox to another. Here I am trying to get the Items count in RadListbox OnTransferred event.

ASPX:
<telerik:RadListBox ID="RadListBox1" runat="server" TransferMode="Copy" TransferToID="RadListBox2"
    AllowTransfer="true" SelectionMode="Multiple" AutoPostBack="true" OnTransferred="RadListBox1_Transferred"
    AutoPostBackOnTransfer="true">
    <Items>
        <telerik:RadListBoxItem runat="server" Text="Item1" />
        <telerik:RadListBoxItem runat="server" Text="Item2" />
        <telerik:RadListBoxItem runat="server" Text="Item3" />
        <telerik:RadListBoxItem runat="server" Text="Item4" />
    </Items>
</telerik:RadListBox>
<telerik:RadListBox ID="RadListBox2" runat="server">
</telerik:RadListBox>
<asp:Label ID="lblTransfer" runat="server"></asp:Label>

C#:
protected void RadListBox1_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e)
{
    if (e.Items.Count > 1 && e.SourceListBox.ClientID == "RadListBox1")
        {
            lblTransfer.Text = "Transfer All to right";
        }
        else if (e.Items.Count == 1 && e.SourceListBox.ClientID == "RadListBox1")
        {
            lblTransfer.Text = "Transfer one Item to right";
        }
        else if (e.Items.Count > 1 && e.SourceListBox.ClientID == "RadListBox2")
        {
            lblTransfer.Text = "Transfer All to left";
        }
        else if (e.Items.Count == 1 && e.SourceListBox.ClientID == "RadListBox2")
        {
            lblTransfer.Text = "Transfer one Item to left";
        }
}

Thanks,
Princy.
0
Troika
Top achievements
Rank 1
answered on 25 Sep 2013, 12:29 PM
this is the same code that i have posted and it dont work when transfering one item to rigth or to left, count is always 0.
also need to know when transfering one item, need to know the item id itself with a normal listbox is just do listbox1.selectedvalue
but why it gets count=0???

http://screencast.com/t/2i4eUh5mScGA
0
Troika
Top achievements
Rank 1
answered on 30 Sep 2013, 10:46 AM
help on this!
0
Troika
Top achievements
Rank 1
answered on 01 Oct 2013, 08:07 AM
i need to catch all items id's and not count.
so the same property as normal listbox.selectedvalue
0
Princy
Top achievements
Rank 2
answered on 01 Oct 2013, 09:26 AM
Hi Troika,

Please have a look into the full code that I tried to access the Text and Value of the SelecetdItem in the RadListBox.

ASPX:
<telerik:RadListBox ID="RadListBox1" runat="server" TransferMode="Copy" TransferToID="RadListBox2"
    AllowTransfer="true" SelectionMode="Multiple" AutoPostBack="true" OnTransferred="RadListBox1_Transferred"
    AutoPostBackOnTransfer="true">
    <Items>
        <telerik:RadListBoxItem runat="server" Text="Item1" Value="1" />
        <telerik:RadListBoxItem runat="server" Text="Item2" Value="2" />
        <telerik:RadListBoxItem runat="server" Text="Item3" Value="3" />
        <telerik:RadListBoxItem runat="server" Text="Item4" Value="4" />
    </Items>
</telerik:RadListBox>
<telerik:RadListBox ID="RadListBox2" runat="server">
</telerik:RadListBox>
<asp:Label ID="lblTransfer" runat="server"></asp:Label>

C#:
protected void RadListBox1_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e)
{
    var SelectedItem = new StringBuilder();
 
    foreach (RadListBoxItem item in e.Items)
    {
        SelectedItem.Append("<li> Text : " + item.Text + " Value : " + item.Value + "</li>");
        lblTransfer.Text = SelectedItem.ToString();
    }
}

Thanks,
Princy.
0
Troika
Top achievements
Rank 1
answered on 01 Oct 2013, 02:15 PM
maybe i'm not explaning very well i have to listboxes with transfer one item to rigth/left and transfer all to rigth or left
so to transfer one item i need to fetch its id thats the problem that code you pasted dont use

e.SourceListBox.ClientID == "RadListBox1"

e.SourceListBox.ClientID == "RadListBox2"

 that i need so i will pick the select value in a foreach from any raddlisbox 
0
Troika
Top achievements
Rank 1
answered on 01 Oct 2013, 02:44 PM
i have put and if before so deetct if its radlistbox1 or 2 but it says items =0 and dont went on foreach when trafering just one item
0
Princy
Top achievements
Rank 2
answered on 03 Oct 2013, 05:30 AM
Hi Troika,

Please try the following code that I tried which works fine at my end.

C#:
protected void RadListBox1_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e)
{
    var SelectedItem = new StringBuilder();
    if (e.Items.Count==1 && e.SourceListBox == RadListBox1)// if selected item count is 1 and sourcelistbox is Radlistbox1
    {
        SelectedItem.Append("<li> Text : " + e.Items[0].Text + " Value : " + e.Items[0].Value + "</li>");
        lblTransfer.Text = SelectedItem.ToString();  
    }
    else if (e.Items.Count == 1 && e.SourceListBox == RadListBox2) //if selected item count is 1 and source listbox is Radlistbox2
    {
        SelectedItem.Append("<li> Text : " + e.Items[0].Text + " Value : " + e.Items[0].Value + "</li>");
        lblTransfer.Text = SelectedItem.ToString();
    }
    else // if selected more than one item
    {
        foreach (RadListBoxItem item in e.Items)
        {
            SelectedItem.Append("<li> Text : " + item.Text + " Value : " + item.Value + "</li>");
            lblTransfer.Text = SelectedItem.ToString();
        }
    }
}

Please provide your full code if it doesn't help you.
Thanks,
Princy.
0
Troika
Top achievements
Rank 1
answered on 03 Oct 2013, 09:35 AM

ok i fixes it with that code
alsi i have a title on each radlistbox but i'm not showing the radlisbox on load and the title appears, i'm hidding the radlistbox on load just when user select a radgrid item i'm using this to show the title:

 

 

.smallModule {

float: left;

position: relative;

left: 226px;

}

.smallModule .title {

font-size: 14px;

padding-bottom: 10px;

}

 

 

<div class="smallModule" style="left: 239px; top: 1px; height: 142px;">

<div class="title">

Patrocinadores não associados:</div>

<telerik:RadListBox ID="RadListBox1" runat="server" Height="190px" Width="218px"

Style="margin-bottom: 10px" AllowTransfer="True" AutoPostBackOnTransfer="true" OnLoad="RadListBox1_Load" Skin="Metro" Sort="Ascending" TransferToID="RadListBox2" OnTransferred="RadListBox1_Transferred" SelectionMode="Single">

 

</telerik:RadListBox>

</div>

need to hide or show depend if radlistbox.visible=true/false

0
Princy
Top achievements
Rank 2
answered on 04 Oct 2013, 05:54 AM
Hi Troika,

Please try the following code snippet that I tried which works fine at my end.

ASPX:
<telerik:RadButton ID="RadButton1" runat="server" Text="Show/Hide RadListBox" AutoPostBack="true"
    OnClick="RadButton1_Click">
</telerik:RadButton>
<br />
<div class="title" id="div1" runat="server" style="display: none">
    RadListBox1
</div>
<br />
<telerik:RadListBox ID="RadListBox1" runat="server" Visible="false" CssClass="title">
    <Items>
        <telerik:RadListBoxItem Text="Item1" runat="server" />
        <telerik:RadListBoxItem Text="Item2" runat="server" />
    </Items>
</telerik:RadListBox>

C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    if (RadListBox1.Visible == false)
    {
      // if RadListBox visibility is false then showing both title and RadListBox
        RadListBox1.Visible = true;
        div1.Style.Add("display", "block");  
    }
    else
    {
      // if RadListBox visibility is true then hiding both title and RadListBox
        RadListBox1.Visible = false;
        div1.Style.Add("display", "none");
    }
}

Thanks,
Princy.
0
Troika
Top achievements
Rank 1
answered on 04 Oct 2013, 09:40 AM
i also need to create a eventbox like herehttp://demos.telerik.com/aspnet-ajax/listbox/examples/populatingwithdata/databaseupdate/defaultcs.aspx i have put a panel but cant add text to that
also when have 2 radlistbox with transfer when i add a title to the second listbox goes down
0
Princy
Top achievements
Rank 2
answered on 07 Oct 2013, 05:09 AM
Hi Troika,

Please try the following code snippet that I tried.

ASPX:
<div>
    RadListBox1
</div>
<telerik:RadListBox ID="RadListBox1" runat="server" TransferToID="RadListBox2" TransferMode="Copy"
    AllowTransfer="true" SelectionMode="Multiple" AutoPostBack="true" OnTransferred="RadListBox1_Transferred"
    AutoPostBackOnTransfer="true">
    <Items>
        <telerik:RadListBoxItem runat="server" Text="Item1" Value="1" />
        <telerik:RadListBoxItem runat="server" Text="Item2" Value="2" />
        <telerik:RadListBoxItem runat="server" Text="Item3" Value="3" />
        <telerik:RadListBoxItem runat="server" Text="Item4" Value="4" />
    </Items>
</telerik:RadListBox>
<div style="margin-left: 150px; margin-top: -121px;">
    RadListBox2
</div>
<telerik:RadListBox ID="RadListBox2" runat="server" Style="margin-left: 150px; height: 50px; position: fixed;">
</telerik:RadListBox>
<asp:Panel ID="Panel1" runat="server" Style="height: 250px; width: 300px; border: 2px solid black;
    margin-top: 100px; position:fixed" Visible="false">
</asp:Panel>

C#:
protected void RadListBox1_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e)
{
    Panel1.Visible = true;
    for (int i = 0; i < e.Items.Count;i++ )
    {
        Panel1.Controls.Add(new LiteralControl("Item Transferred"));
        Panel1.Controls.Add(new LiteralControl("<br/>"));
    }
}

Thanks,
Princy.
0
Troika
Top achievements
Rank 1
answered on 08 Oct 2013, 09:59 PM
i have made an screenshot for you to see because this is very starnge that the radbox wont appear and they are visible , they wont appear i cant understand why this is happening http://screencast.com/t/9j4eZ6eLj

radgrid has this options:

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" CellSpacing="0" GridLines="None" Skin="Metro" PageSize="5" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">

<ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" EnablePostBackOnRowClick="True" Selecting-AllowRowSelect="True">

<Selecting AllowRowSelect="True" />

<Scrolling AllowScroll="True" UseStaticHeaders="True" />

</ClientSettings>

0
Troika
Top achievements
Rank 1
answered on 09 Oct 2013, 08:28 PM
update see this screen:

why items loaded on add items appear insetad of the one's loaded from db

so it appears radlistboxitem1,2,3,4,5, instead of the others they just appear when i click transfer.
i also want that the radlistbox just appear when radgrid selectchanged índex is clicked but radlistbox_load dont fire see:http://screencast.com/t/DLU5tbOC
0
Fatma
Top achievements
Rank 1
answered on 27 Jul 2016, 09:04 PM

I follow this link and it works with me

 

http://www.telerik.com/support/kb/aspnet-ajax/listbox/details/transfer-to-multiple-radlistboxes-using-drag-and-drop

 

 

Tags
ListBox
Asked by
Troika
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Troika
Top achievements
Rank 1
Fatma
Top achievements
Rank 1
Share this question
or