HOT TO GET VALUE IN LABEL OF MULTI SELECTED LISTBOX?

Samuel Fernandes

Total Post:159

Points:1117
Posted by  Samuel Fernandes
C#  .NET 
C#
 962  View(s)
Ratings:
Rate this:
Hi

How to get listbox multiple selected values in label or string.
I have bind data from table in listbox then when i select multi values then this display in label or string
when i try get values in label then display System.Data.Dataview multi time
my code

  for (i = 0; i < lstcsuspectcode.SelectedItems.Count; i++)
  {

  label18.Text = label18.Text + " " + lstcsuspectcode.SelectedValue;
  
  }
  1. Royce Roy

    Post:149

    Points:1043
    Re: Hot to get value in label of Multi Selected Listbox?

    You can try this code.

     string s = "";
            foreach (ListItem li in ListBox1.Items) {

                if (li.Selected == true) {
                    s = s +" "+ li.Value;
                }

            }

      Modified On Oct-13-2017 06:42:27 AM
  1. Mark Devid

    Post:102

    Points:714
    Re: Hot to get value in label of Multi Selected Listbox?

    HI Guys try this...

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsFormsApplication6
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                listBox1.Items.Add("a");
                listBox1.Items.Add("b");
                listBox1.Items.Add("c");
                listBox1.Items.Add("d");
            }

            private void button1_Click(object sender, EventArgs e)
            {
               
                int i;
                for (i = 0; i < listBox1.SelectedItems.Count; i++)
                {

                    label1.Text = label1.Text + " " + listBox1.SelectedItem.ToString();

                }
            }
        }
    }

      Modified On Oct-13-2017 06:41:52 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!