Hi,
I'm attempting to show the end user some feedback on the items they've checked in a combobox and I want to send the checkedItems to a ListBox underneath showing what the user has checked. I'm having no luck with what I am trying.
Something like this:
ListBox1.Items.Add(ComboBox.CheckedItems.ToString());
5 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 27 Sep 2012, 05:10 AM
Hi Gary,
I suppose you want to copy the checked RadComboBoxItems to the RadListBox. Following is the sample code that I tried.
ASPX:
C#:
Hope this helps.
Regards,
Princy.
I suppose you want to copy the checked RadComboBoxItems to the RadListBox. Following is the sample code that I tried.
ASPX:
<
telerik:RadComboBox
ID
=
"RadComboBox1"
runat
=
"server"
CheckBoxes
=
"true"
>
<
Items
>
<
telerik:RadComboBoxItem
Text
=
"RadComboBoxItem1"
/>
<
telerik:RadComboBoxItem
Text
=
"RadComboBoxItem2"
/>
<
telerik:RadComboBoxItem
Text
=
"RadComboBoxItem3"
/>
<
telerik:RadComboBoxItem
Text
=
"RadComboBoxItem4"
/>
<
telerik:RadComboBoxItem
Text
=
"RadComboBoxItem5"
/>
<
telerik:RadComboBoxItem
Text
=
"RadComboBoxItem6"
/>
</
Items
>
</
telerik:RadComboBox
>
<
asp:Button
ID
=
"btn"
runat
=
"server"
text
=
"transfer"
OnClick
=
"btn_Click"
/>
<
telerik:RadListBox
ID
=
"RadListBox2"
runat
=
"server"
>
</
telerik:RadListBox
>
C#:
protected
void
btn_Click(
object
sender, EventArgs e)
{
foreach
(RadComboBoxItem item
in
RadComboBox1.CheckedItems)
{
RadListBoxItem itm =
new
RadListBoxItem();
itm.Text = item.Text;
RadListBox2.Items.Add(itm);
RadListBox2.DataBind();
}
}
Hope this helps.
Regards,
Princy.
0

GARY078
Top achievements
Rank 1
answered on 28 Sep 2012, 08:16 AM
Thanks Princy!
Would this method still work with a databound ComboBox?
Would this method still work with a databound ComboBox?
0
Accepted

Princy
Top achievements
Rank 2
answered on 28 Sep 2012, 09:07 AM
Hi,
You can use the same approach for a data bound combobox as well.
aspx:
C#:
Regards,
Princy.
You can use the same approach for a data bound combobox as well.
aspx:
<
telerik:RadComboBox
ID
=
"RadComboBox1"
DataSourceID
=
"SqlDataSource2"
DataTextField
=
"EmployeeID"
DataValueField
=
"EmployeeID"
runat
=
"server"
CheckBoxes
=
"true"
>
</
telerik:RadComboBox
>
<
asp:Button
ID
=
"btn"
runat
=
"server"
text
=
"transfer"
OnClick
=
"btn_Click"
/>
<
telerik:RadListBox
ID
=
"RadListBox2"
runat
=
"server"
>
</
telerik:RadListBox
>
protected
void
btn_Click(
object
sender, EventArgs e)
{
foreach
(RadComboBoxItem item
in
RadComboBox1.CheckedItems)
{
RadListBoxItem itm =
new
RadListBoxItem();
itm.Text = item.Text;
RadListBox2.Items.Add(itm);
RadListBox2.DataBind();
}
}
Regards,
Princy.
0

GARY078
Top achievements
Rank 1
answered on 16 Oct 2012, 12:31 PM
Is there a client-side method of achieving the same result?
I can get the items to transfer from combo to listbox, but what do i set the "item.set_text" property as?
At the moment the itemText is just being passed as "Object"...
I can get the items to transfer from combo to listbox, but what do i set the "item.set_text" property as?
At the moment the itemText is just being passed as "Object"...
function
addItem(sender, eventArgs) {
var
itemText = $find(
"<%=BusinessRolesDDL.ClientID %>"
).get_checkedItems();
var
listBox = $find(
"<%=BusinessRolesAdd.ClientID %>"
);
if
(sender.get_checkedItems() <= 0) {
alert(
"Please choose functional roles to add."
);
return
false
;
}
listBox.trackChanges();
//Instantiate a new client item
var
item =
new
Telerik.Web.UI.RadListBoxItem();
item.set_text(itemText);
listBox.get_items().add(item);
item.scrollIntoView();
listBox.commitChanges();
return
false
;
}
0
Accepted
Hi Gary,
In order to implement transfer client-side, you should loop trough all the checked items from RadComboBox and create a RadListBoxItem with the corresponding Text. I have prepared a sample project for you, so you could implement the suggested approach. Find the attached sample.
Greetings,
Nencho
the Telerik team
In order to implement transfer client-side, you should loop trough all the checked items from RadComboBox and create a RadListBoxItem with the corresponding Text. I have prepared a sample project for you, so you could implement the suggested approach. Find the attached sample.
Greetings,
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.