Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to add checked items from checkboxlist to listbox

How to add checked items from checkboxlist to listbox

Scheduled Pinned Locked Moved ASP.NET
helptutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vivek886
    wrote on last edited by
    #1

    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.

    S V T 3 Replies Last reply
    0
    • V vivek886

      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.

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      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

      V 1 Reply Last reply
      0
      • S Sandeep Mewara

        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

        V Offline
        V Offline
        vivek886
        wrote on last edited by
        #3

        Sandeep thanx for reply but its adding previously checked item again and again.

        S 1 Reply Last reply
        0
        • V vivek886

          Sandeep thanx for reply but its adding previously checked item again and again.

          S Offline
          S Offline
          Sandeep Mewara
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • V vivek886

            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.

            V Offline
            V Offline
            vvashishta
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • V vivek886

              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.

              T Offline
              T Offline
              taha bahraminezhad Jooneghani
              wrote on last edited by
              #6

              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!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups