473,503 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop Through ASP Table Object

LacrosseB0ss
113 New Member
I have a table object (not html, or database table, <asp:Table>) on my form that has data in it. When the user clicks a "Submit" button on a form, I would like to loop through this table row by row picking up the information in it and writing it to the database.

I was using the code below but I got an error (invalid index or something) @ the line tblTable.Rows(i).Cells(j).Text. Can anyone help please?

Expand|Select|Wrap|Line Numbers
  1. ASP:
  2. For i = 1 To tblTable.Rows.Count 'exclude header row
  3.             For j = 1 To numCols 'I don't need the 1st column
  4.                 empArray(j) = CStr(tblTable.Rows(i).Cells(j).Text)
  5.             Next j
  6.             strList &= strArray(1) & " - " & strArray(2) & ", "
  7.         Next i
  8.  
I'm still trying to figure this out so some of the style sucks due to not knowing entirely what's going on. Thanks in advance

- LB
Nov 14 '06 #1
2 5375
willakawill
1,646 Top Contributor
I have a table object (not html, or database table, <asp:Table>) on my form that has data in it. When the user clicks a "Submit" button on a form, I would like to loop through this table row by row picking up the information in it and writing it to the database.

I was using the code below but I got an error (invalid index or something) @ the line tblTable.Rows(i).Cells(j).Text. Can anyone help please?

Expand|Select|Wrap|Line Numbers
  1. ASP:
  2. For i = 1 To tblTable.Rows.Count 'exclude header row
  3.             For j = 1 To numCols 'I don't need the 1st column
  4.                 empArray(j) = CStr(tblTable.Rows(i).Cells(j).Text)
  5.             Next j
  6.             strList &= strArray(1) & " - " & strArray(2) & ", "
  7.         Next i
  8.  
I'm still trying to figure this out so some of the style sucks due to not knowing entirely what's going on. Thanks in advance

- LB
Hi. How is the empArray declared?
Also what is the strArray and why are the exact same values being assigned to strList numCols times?
Nov 14 '06 #2
LacrosseB0ss
113 New Member
sorry, they are strings.

I figured out what the problem was. I have a header row for my table and nothing else until the code populates it with employees that are read from a listbox on another form. From this form (where the table is) a button is clicked to submit information or make changes.

When the "Submit" button is clicked, all information is written to the database. However, the form is also posted back and the Table Rows don't stick around. So, when it hit the line Table.Rows(1).Cells(1).Text, it doesn't exist and the error is produced.

I've since changed the code and now when a row is added to the table, the employee being added is also added to a String array of all employees. I will input this array into the database (unless there's a way to NOT postback the form, or to not lose the table's rows/data).

Thanks for your help
- LB
Nov 14 '06 #3

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

Similar topics

0
2763
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get...
2
4064
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
47
12023
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
2
1413
by: Phil | last post by:
I have an aspx page that contains 5 tables. Each table I have Named tblSection1, tblSection2, tblSection3, tblSection4, tblSection5 respectively and reside in a corresponding panel for collapse and...
2
2686
by: JC | last post by:
Hi, I have a database that imports 4 reports to my "data" table, each report has its own identifier. Then I have a table with Analysts with the report identifier that they are to be assigned to. ...
52
6269
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
4
1583
by: =?Utf-8?B?VG9kZCBKYXNwZXJz?= | last post by:
Hey guys, Is there ANY way to accomplish this: (see below)? Basically, I want to have a loop (a < 3 is just for testing purposes, it will be an underermined amount). In this loop, I want to be...
2
9416
by: rn5a | last post by:
In a ASP applicatiuon, the FOrm has a textbox & a select list where the admin can select multiple options. Basically the admin has to enter the name of a new coach in the textbox & select the...
8
6463
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
10
2901
by: fig000 | last post by:
HI, I'm new to generics. I've written a simple class to which I'm passing a generic list. I'm able to pass the list and even pass the type of the list so I can use it to traverse it. It's a...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.