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. Dynamically creating controls and accessing them

Dynamically creating controls and accessing them

Scheduled Pinned Locked Moved ASP.NET
questiondatabasehelp
3 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.
  • M Offline
    M Offline
    Matt Cavanagh
    wrote on last edited by
    #1

    Hi guys. Im doing a project at the moment that requires the user to select what categories they want to be registered for via check boxes. BUT there arent set categories(and no set number), so they must be read from the database, and then the controls must be generated. So what I have done is put a place holder and then just create new controls in the while read loop of the database. Two problems though: 1) How do I name these(incrementally?)? I cant say

    CheckBox chkBx + "i" = new CheckBox();

    1. Even if I could incrememnt their names how would I see what they had checked once they click ok? I thought about

    lblStuff.Text += ""

    (ignore the xmlns :-/ ) But that still leaves the second problem. Am I going about this the wrong way? Thanks guys :)

    S 1 Reply Last reply
    0
    • M Matt Cavanagh

      Hi guys. Im doing a project at the moment that requires the user to select what categories they want to be registered for via check boxes. BUT there arent set categories(and no set number), so they must be read from the database, and then the controls must be generated. So what I have done is put a place holder and then just create new controls in the while read loop of the database. Two problems though: 1) How do I name these(incrementally?)? I cant say

      CheckBox chkBx + "i" = new CheckBox();

      1. Even if I could incrememnt their names how would I see what they had checked once they click ok? I thought about

      lblStuff.Text += ""

      (ignore the xmlns :-/ ) But that still leaves the second problem. Am I going about this the wrong way? Thanks guys :)

      S Offline
      S Offline
      SachinKumar M
      wrote on last edited by
      #2

      you can use CheckBoxList instead of creating Checkbox Dynamically.. and for CheckBoxList you can Bind the values form Database.. and onclick of OK, you can loop through CheckBoxList.Items.Count to check which is Selected and You can take only Selected Values..

      M 1 Reply Last reply
      0
      • S SachinKumar M

        you can use CheckBoxList instead of creating Checkbox Dynamically.. and for CheckBoxList you can Bind the values form Database.. and onclick of OK, you can loop through CheckBoxList.Items.Count to check which is Selected and You can take only Selected Values..

        M Offline
        M Offline
        Matt Cavanagh
        wrote on last edited by
        #3

        Perfect :D Thanks, really appreciate it!

        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