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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieving dynamic control data 1

Status
Not open for further replies.

gtrscott

IS-IT--Management
Dec 31, 2003
21
0
0
US
Hi All,

An app I'm working on creates a table web control with a dynamic number of rows containing labels text boxes and list boxes. I assign names like text1,list1 for row 1 text2, list2 for row 2 etc.

I would like to retrieve them in a loop like the schematic example below :


for i = 1 to MyTable.Rows.Count
set TextControl = controls("Text" & i)
set ListControl = controls("List" & i)

SomeTextValue = TextControl.Text
SomeListItem = ListControl.SelectedItem
'Write the data to a database and move on
next

However, I can't figure out how to cast the controls to an object by their name.

Does anybody have a solution?

Thanks!!!!
 
I believe, there is a CType function in VB.
Code:
for i = 1 to MyTable.Rows.Count
 dim TextControl as TextBox = CType(MyTable.Rows(i).FindControl("Text" & i), TextBox)
 dim ListControl as ListBox = CType(MyTable.Rows(i).FindControl("List" & i), TextBox)
 SomeTextValue = TextControl.Text
 SomeListItem = ListControl.SelectedItem 
 'Write the data to a database and move on
  next
And I think you need to dynamicaly assign IDs to the controls as well, not only names.
 
Thanks that worked perfectly!

I mis-spoke about the names. I'm already assigning ID's when I build the table.

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top