473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dynamic Checkboxes? Or a different way all together

New to asp.net. Pretty familiar with vb.net. This maybe a simple question but I can't seem to find a good answer to it anywhere or at least an alternative/better way.

I am trying to dynamically create checkboxes for items that need to be selected and updated in the database.

The code below will allow those checkboxes to be created and display on the web form and work correctly. However, when I try to access them from another function/Sub I can not.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub GetData( orderNumber as integer)
  3.  
  4.         sqlQueryString = "exec OrderItems " & orderNumber
  5.  
  6.         Dim objDs As DataSet
  7.         Dim objSQLDa As SqlDataAdapter
  8.         Dim objRow As DataRow
  9.  
  10.         objDs = New DataSet()
  11.  
  12.         objSQLDa = New SqlDataAdapter(sqlQueryString, ConnString)
  13.  
  14.         objSQLDa.Fill(objDs, "Dropship Data")
  15.  
  16.  
  17.         Dim chk(objDs.Tables(0).Rows.Count) As CheckBox
  18.         i = 0
  19.  
  20.         For Each objRow In objDs.Tables(0).Rows
  21.  
  22.             sItemID = "<strong>ItemID:</strong> " & objRow("ItemID").ToString & "<br>" & CrLf
  23.             sBrand = "<strong>Brand:</strong> " & objRow("Brand").ToString & "<br>" & CrLf
  24.             sDropShip = "<strong>Dropship:</strong> " & objRow("dropship").ToString & "<br>" & CrLf
  25.  
  26.             chk(i) = New CheckBox
  27.  
  28.             chk(i).ID = objRow("id").ToString
  29.             chk(i).Text = sItemID & sBrand & sDropShip
  30.  
  31.             Me.productData.Controls.Add(chk(i))
  32.             i += i
  33.         Next
  34. End Sub
  35.  
Now I can't get the data back after submitting the form. It is really easy to work with the controls that are created in the design view. But I don't know how to work with the controls created in the code.

I would like to check the boxes that are needed. Click a submit button. Then have the click button event handler loop through the ID's for the checked boxes and process a stored proc that will do all the updates in the DB that need to be done.

Something like:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub DoThisWhenTheButtonIsPressed()
  3.  
  4.    For i=0 to uBound(chk)
  5.         if chk(i).checked then
  6.             DoStoredProc(chk(i).ID)
  7.         end if
  8.    Next
  9.  
  10. End Sub
  11.  
  12.  
It is really easy to work with controls that are created in the design view. I just can't find out how to get the data from the controls that are created in the code.

Also is there a method for view all the post back data from the form? Something like:

response.write me.form1.postbackdata


Thanks for your help!
Feb 26 '10 #1

✓ answered by semomaniz


3 1869
semomaniz
210 Expert 100+
Hope this will help

http://www.dotnetspider.com/resource...rom-e-cod.aspx
Feb 27 '10 #2
Its like someone back in 2004 was thinking, "Hey, this guy is gonna come looking for this later. I'd better get it up now."

Exactly what I was looking for, thanks!!
Feb 28 '10 #3
Frinavale
9,735 Expert Mod 8TB
The code posted in the article that you've been linked to will probably work for now but you could possibly run into problems in the future because you are instantiating the control in your Page Load event. You should instead move this code to your Page Init event. The reason is outlined in this article about how to use dynamic controls in ASP.NET

-Frinny
Mar 1 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: middletree | last post by:
Hate to post this in a separate post, but felt that the last thread was too far down to get noticed. It is called dynamic checkboxes, and it contained some good advice for me, but it led to...
8
by: DylanM | last post by:
I have some checkboxes that are generated from the results of a database search. At the moment, the checkboxes are part of a table making up a form. Users are going through the form, clicking the...
2
by: Amy Snyder | last post by:
This is my firt .NET project so please bear with me. I have a form of checkboxes and all I want to do is loop through them all after the page has been submitted and have their values added to a...
2
by: trank | last post by:
I created some checkboxes(<input type=checkbox>) dynamically,and then I'd like to access these checkboxes in code behind using C#. For they are not standard controls like Windows Checkbox, I can't...
3
by: Jack Black | last post by:
Using VS.Net 2k3 to build ASP.Net app with VB code-behind pages... Hi, all! I've been struggling with getting a dynamically-generated CheckBoxList generated. I've finally been able to get the...
34
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript...
2
by: GustavoBrust | last post by:
Hello everyone. I'm having a problem with a search I want to make. It's like this: The user can choose about 15 checkboxes to be his search pattern. According to the combination of...
0
by: TarekSaad | last post by:
I am using VB2005 and have created a dynamic list of checkboxes and depending on which file the user selects there may be between 1 and 20 checkboxed that appear in a form. The user then checks...
2
by: Beacherboy | last post by:
Hi All, This one is a bit complex, so I'll try to be as logical explaining the issue as humanily possible. ASP/VBScript/MySQL Issue: Creating dynamic variables while there is an unknown...
2
by: scottSD | last post by:
Hi everyone. this is my first post here, but i've found quite a bit of great information from reading the forums in the past. i'm not sure if what i'm trying to do is possible or not, but here it...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.