Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Dynamically created controls to database

Status
Not open for further replies.

AppzDev

MIS
Oct 9, 2002
57
US
I've got a checkbox list with 12 items to choose from. If one of them is chosen i postback and dynamically add 3 controls to a panel. Here's a snippet of the code i'm using...

For i = 0 to cblPatientGoals.Items.Count -1
If cblPatientGoals.Items(i).Selected

Dim myLabel as new Label ()
myLabel.Text &= cblPatientGoals.Items(i).Text

Dim myCheckBox as New CheckBoxList ()
myCheckBox.Items.Add(new ListItem("Met", "Met"))
myCheckBox.Items.Add(new ListItem("Unmet", "Unmet"))
myCheckBox.RepeatDirection = RepeatDirection.Horizontal
myCheckBox.ID = "cGoals" & (i + 1)
'Response.write(myCheckBox.id)
Dim myTextBox as New TextBox ()
myTextBox.ID = "tGoals" & (i + 1)
myTextBox.Style("Width") = "350px"

panel1.Controls.Add(myLabel)
panel1.Controls.add(myCheckBox)
panel1.Controls.add(myTextBox)
End If
Next

All of this works as intended. When a user clicks the first item in the checkboxlist i have a label created, a checkboxlist with 2 listitems Met and Unmet created as well as a textbox. The respective ID's of that checkboxlist and textbox is cgoals1 and tgoals1. My dilemma is this...how do i update a database?

In my table i have 24 fields (cgoals1, tgoals1, cgoals2, tgoals2 etc) however i'm stuck writing the INSERT INTO statement b/c i'm dynamically creating controls which are dependent on what the user clicks.

I'm looking for some ideas on either how to update this or a better method of doing what i'm doing...i'm fully open to any suggestions anyone can give me.

Thanks
dc.
 
Presumably, there is a GoalID or something in the db. Why not use that value instead of i in your checkboxID? A bit of ugly parsing of the control name could get you what you want.

Brian Begy
BugSentry - Automatic error reporting for .NET and COM
 
What you would have to do is to loop through all the controls on the page and find out which ones you have and create the SQL stament. Ugly as Brian has pointed out, but it can be done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top