I have done this several ways and i guess im just curious how others tackle this. I am getting ready to do this and then i was like " i wonder if there is a better way". So here we go.
I am reading values from the DB and for each record i will create a textbox.
As i loop i will have a counter. It will look like this
Code:
<%
i = 0
Do While Not objRS.EOF
i = i + 1
%>
<tr>
<td><input type="text" name="txtHrs_<%=i%>"></td>
</tr>
<%
objRS.MoveNext
Loop
%>
For the sake of an example, lets say i loop 3 times. So i have
txtHrs_1
txtHrs_2
txtHrs_3 For the names of my textboxes.
Now when i submit the form and write back to the DB, im going to do
something like this.
Code:
For i = 1 to 3
hrs = Request.form("txthrs_" & i)
'do my db stuff and add this value
Next
Now this example is for a set number of records, this wont be the case w/ the application.
Also if some of the syntax is off thats ok, this was just an example, i did not include all the code, such as for i = 1 to 3, well yes i would not hard code the 3, that would depend on how many records were looped, etc.
Any way i just wanted to see what other options i have available as this is the way i usually do it, but i thought about using the Forms collection, but have never done that and im not sure if the Forms collection will just return my text box or if its going to return the buttons, radio, check, text, tetxtarea, etc.
Or it might just be that the way i do it is perfectly fine.
The form collection will return everything, regardless of its control type. Although, it will not return radio boxed and check boxes if they have not been checked. This is a browser thing, though, as the client will not pass data like this to the server unless it has to. You are actually using the forms collection everytime you do something like Request.Fom("fff").
If you were using the right cursortype, you could use a for loop here and get rid of the do...while
Code:
For i = 0 To objRS.RecordCount
%>
<tr>
<td><input type="text" name="txtHrs_<%=i%>"></td>
</tr>
<%
objRS.MoveNext
Next
Bookmarks