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
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.
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
so the same property as normal listbox.selectedvalue
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.
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 raddlisboxPlease 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.
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
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.
also when have 2 radlistbox with transfer when i add a title to the second listbox goes down
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.
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>
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
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