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. QUestions regarding the Checkbox list in ASP.Net

QUestions regarding the Checkbox list in ASP.Net

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasedata-structurestutorial
4 Posts 3 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.
  • S Offline
    S Offline
    sam L 0
    wrote on last edited by
    #1

    I have a checkbox list that is being populated by a database object. User should be able to select more than one option from the checkbox list....now I wanna be able to grab all the values that the user is selecting and be able to put them into a variable....now since there could be more than one value that a user may select, I can't put save them into a string variable...it has to be a string array or something along those lines...to be able to hold multiple variables. Now can someone please post something on here that shown me how to do that. Thanks

    S N 2 Replies Last reply
    0
    • S sam L 0

      I have a checkbox list that is being populated by a database object. User should be able to select more than one option from the checkbox list....now I wanna be able to grab all the values that the user is selecting and be able to put them into a variable....now since there could be more than one value that a user may select, I can't put save them into a string variable...it has to be a string array or something along those lines...to be able to hold multiple variables. Now can someone please post something on here that shown me how to do that. Thanks

      S Offline
      S Offline
      Sun Rays
      wrote on last edited by
      #2

      Hi, you can use ArrayList and can add selected values in the ArrayList.

      Thanks, Sun Rays To get something you must have to try once. My Articles

      1 Reply Last reply
      0
      • S sam L 0

        I have a checkbox list that is being populated by a database object. User should be able to select more than one option from the checkbox list....now I wanna be able to grab all the values that the user is selecting and be able to put them into a variable....now since there could be more than one value that a user may select, I can't put save them into a string variable...it has to be a string array or something along those lines...to be able to hold multiple variables. Now can someone please post something on here that shown me how to do that. Thanks

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        Use a generic List<>, which will be type safe. Check this

        List<string> objList = new List<string>();
        foreach (ListItem item in CheckBoxList1.Items)
        {
        if (item.Selected)
        objList.Add(item.Text);
        }

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        S 1 Reply Last reply
        0
        • N N a v a n e e t h

          Use a generic List<>, which will be type safe. Check this

          List<string> objList = new List<string>();
          foreach (ListItem item in CheckBoxList1.Items)
          {
          if (item.Selected)
          objList.Add(item.Text);
          }

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

          S Offline
          S Offline
          sam L 0
          wrote on last edited by
          #4

          Hi there, thanks for the speedy response... well I just started out with .Net so I really didnt know about these generic classes in 2.0, thanks for pointing out, I looked at them and the sample code you posted, Following is what I kinda came up with. //Member Level variable string mJurisdictionSelected = null; protected void GetUserSelectedValues() { string dateSelected = this.mDateRestrictor.SelectedItem.Value.ToString(); //this.dateTest.Text = dateSelected; //for (int num = 0; num < mJuristictionCheckBoxList.Items.Count; num++) //string[] jurisdictionName; string jurisdictionName = null; System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(); foreach (ListItem item in this.mJuristictionCheckBoxList.Items) { //ArrayList jurisdictionName = new ArrayList(); if (item.Selected) { list.Add(item.Text); //jurisdictionName = item.Text.ToString(); // this.StateTest.Text = jurisdictionName.ToString(); } } this.mDateSelected = dateSelected.ToString(); if (!string.IsNullOrEmpty(jurisdictionName)) //this.mJurisdictionSelected = jurisdictionName.ToString(); this.mJurisdictionSelected = list.ToString(); } Now as you can see, after retrieving the values (from drop down) into string variable dateSelected and from checkboxlist into string variable mJurisdictionSelected, I need to pass them to our company's middle tier folks...so thats why I'm putting them in member level variables....the question regarding the implemenation you showed me is that " should I just create System.Collections.Generic.List as a member level thing, outside of the function and then directly keep the values into the list of type System.Collections.Generic.List. Instead of putting them into string mJurisdictionSelected? I mean the issue is that user could be selecting more than one value from the checkbox list so is this implemenation you told me about would be able to hanle more than one entry selected by user in the checkbox list?????? Or do I need like an array or something??? Please help?? Thanks Sam

          ----------------------------- If you don't go after what you want, you'll never have it. If you don't ask, the answer is always no. If you don't step forward, you're always in the same place. -Nora Roberts

          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