473,657 Members | 2,348 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 5380
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).C ells(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
2773
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 it from the db table is: ''Retrieve the Registration Identification Number strRegisterID = Rs("Register_ID") Prior to testing my code and actually updating the db, I''m trying to write it to the page to make sure their isn''t a loop or massive...
2
4073
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 Oranges. The user selects from a drop down menu, between 1-10 of each and clicks submit. The resulting page will display a NEW form, with rows and a list of fields for the amount of each items selected.
47
12174
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) { int result = 0; for(int i = 1;i <=iterations;i++) { result += i;
2
1423
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 placement purposes. I have a loop in the code behind that will add rows and cells for each table based on what is needed for that particular table. What I need to do is be able to add a row to my table based on the pass of the loop I am in....
2
2692
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. What I need to do is loop the two tables so that an Analyst is assigned to each record in the "data" table based on the identifier. For example, I have one analyst that needs to be assigned to the "H" report records, one analyst that needs to...
52
6312
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 variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
4
1588
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 able to create a new cell each time. In this cell, I want the variable name to change. Is this at ALL possible? I've never been able to figure this out in some of the other languages. Any help would GREATLY be appreciated.
2
9427
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 soccer clubs which he will be coaching; thus he can select only one soccer club for a new coach or multiple soccer clubs. This is how I am trying it: When this Form will be submitted, the new coaches name will be inserted in a MS-Access DB table...
8
6480
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 using a code loop and an INSERT INTO query. About 800,000 records of raw text. Later, I can then loop through and parse these 800,000 strings into usable data using more code. The problem I have is that the conversion of the text file, using a...
10
2935
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 generic list of business objects. I'm able to see that the type is the correct one in the debugger. However when I try to traverse the list using the type I can't compile. The same type variable I've verified as being passed
0
8399
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8606
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.