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. General Programming
  3. C#
  4. How to Set multiple items as selected in a ListBox with c# [modified]

How to Set multiple items as selected in a ListBox with c# [modified]

Scheduled Pinned Locked Moved C#
csharpasp-nethelptutorial
2 Posts 2 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.
  • W Offline
    W Offline
    waldj2000
    wrote on last edited by
    #1

    I have a ListBox set as Multiselect. I am populating the table thruough asp.net code. But I am using another dataset to get the items that should be selected. The only item that ends up selected is the last item in the dataset, and I know in several cases there are at least two items that should be selected. The code I am using for setting the selected items is: DataSet ds1 = SqlHelper.ExecuteDataset(ConnStr, "StoredProd", Parm); lbRequestTime.SelectionMode = ListSelectionMode.Multiple; foreach (DataRow row in ds1.Tables[0].Rows) { lbRequestTime.SelectedValue = row["PerfTimeId"].ToString(); } Any help on how to get the Mulitple selected items selected would be great. Thanks, Doug

    modified on Tuesday, March 25, 2008 9:33 AM

    V 1 Reply Last reply
    0
    • W waldj2000

      I have a ListBox set as Multiselect. I am populating the table thruough asp.net code. But I am using another dataset to get the items that should be selected. The only item that ends up selected is the last item in the dataset, and I know in several cases there are at least two items that should be selected. The code I am using for setting the selected items is: DataSet ds1 = SqlHelper.ExecuteDataset(ConnStr, "StoredProd", Parm); lbRequestTime.SelectionMode = ListSelectionMode.Multiple; foreach (DataRow row in ds1.Tables[0].Rows) { lbRequestTime.SelectedValue = row["PerfTimeId"].ToString(); } Any help on how to get the Mulitple selected items selected would be great. Thanks, Doug

      modified on Tuesday, March 25, 2008 9:33 AM

      V Offline
      V Offline
      Vimal Raj
      wrote on last edited by
      #2

      Hi, you can use the following code ListItem li; foreach (DataRow row in ds1.Tables[0].Rows) { li = lbRequestTime.Items.FindByValue(row["PerfTimeId"].ToString()); if (li != null) li.Selected = true; } Do let me know if you need more info. Cheers...

      Happy Programming, Vimal Raj MCAD.Net www.techisolutions.blogspot.com

      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