How to add checked items from checkboxlist to listbox
-
I was trying this code ListBox1.Items.Add(checkboxlist1.SelectemItem.ToString()); but its not adding the item to listbox. Only adds first item to list box.... please consider and help for it.
SelectedItem : Gets the selected item with the lowest index in the list control, details here.[^] Go in a loop , find all the items that are marked checked and use them.
foreach (ListItem item in lstMultipleValues.Items)
{
//check if selected and then add it to the new list
if (item.Selected)
AnotherList.Items.Add(item);
}Sandeep Mewara [My last tip/trick]: Browser back button issue after logout
-
SelectedItem : Gets the selected item with the lowest index in the list control, details here.[^] Go in a loop , find all the items that are marked checked and use them.
foreach (ListItem item in lstMultipleValues.Items)
{
//check if selected and then add it to the new list
if (item.Selected)
AnotherList.Items.Add(item);
}Sandeep Mewara [My last tip/trick]: Browser back button issue after logout
-
Not sure what you mean by it. It's not adding all the items marked? Further, to avoid reference issues, create a new listitem every time you find that the checklistbox item is selected and then add that to the new list.
Sandeep Mewara [My last tip/trick]: Browser back button issue after logout
-
I was trying this code ListBox1.Items.Add(checkboxlist1.SelectemItem.ToString()); but its not adding the item to listbox. Only adds first item to list box.... please consider and help for it.
Make a loop iteration on the CheckBoxList on counter from Zero (0) till the item count in CheckBoxList. then inside for loop, at every index put a if condition for, if the item at that index of CheckBoxList either the check box is checked or not,, if it is checked then add that item to a temporary created Data Table or DataSet, every time the condition falls true... as the loop ends now Data Table or DataSet is populated with only Checked items from CheckBoxList.. Now bind this Data Table or DataSet to a ListBox .
- Happy Coding - Vishal Vashishta
-
I was trying this code ListBox1.Items.Add(checkboxlist1.SelectemItem.ToString()); but its not adding the item to listbox. Only adds first item to list box.... please consider and help for it.
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox1.Items.Add(CheckBoxList1.SelectedItem);
}you have to add a ListItem in add method not a string! and listbox selection mode should be multiple!