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!

Dynamic controls question

Status
Not open for further replies.

PsychoCoder

Programmer
May 31, 2006
140
US
I have a webform when I create dynamic textboxes depending on how many times the user clicks the "Add" link. When they hit the "Submit" button Im trying to loop through the dynamic textboxes and insert the information into the database.

Im trying to do this inside a loop (as Im sure thats the only way to do it since they were created in a loop and the only difference in the name is the counter number.

I have this loop:

Code:
For iCount = 0 To Session("NetTextBoxCount")
  sSQL = "INSERT INTO "
  sSQL &= "dbo.Turbo_Change_Log_Items(change_log_id,change_object, change_object_changes, change_object_type, date_entered)"
  sSQL &= "SELECT"
  sSQL &= "@change_log_id,@change_object,@change_object_changes,1,GETDATE()"

  Command = New SqlCommand(sSQL, Connection)
  Command.Parameters.AddWithValue("@change_log_id", CType(NewId, Integer))
  Command.Parameters.AddWithValue("@change_object", [b]FindControl(object_ & iCount)[/b])
Next

The line in bold is giving me the problem, I cant seem to use the name of the textbox object_ and concat the counter value to it (ie; object_1, object_2, etc..).

Does anyone have any ideas on how I can do this?

Senior Qik III,.Net,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
I'm not exactly sure about the VB formatting of this, but try something like ....

Code:
Dim txt as Textbox 

txt = CType(FindControl(object_ & iCount), TextBox)

Command.Parameters.AddWithValue("@change_object", txt.Text)
 
I figured it out, I had to write it like

Code:
Command.Parameters.AddWithValue("@change_object", CType(FindControl("object_" & iCount), TextBox).Text)

Senior Qik III,.Net,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
ya more compact than mine heh... was spending more time trying to remember the vb syntax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top