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

Mass SQL Update from Repeater

Status
Not open for further replies.

skispray

Programmer
Feb 28, 2003
16
US
I have a repeater that has many rows in it and the user can modify the data using the controls in the repeater. The number of rows will differ for each user. For example, there could be 100 rows in the repeater and the user can click the Yes or No radiobutton to answer the question for that row.

I'd like to have one button at the bottom of the page to update all of the rows. This will save the user from having to push "Update" for each row. How can this be coded?
 
ski: I've got to run -- but here is a sub I use to catch all selected values in a listbox set to multi-select. Perhaps there is a clue in there for you -- no doubt there are many ways to approach this problem - don't have time at this moment to test - just dropping in this slice of code in case it might be useful.

Dim s As String
Dim r As String
Dim i, n As Integer
'Make sure at least one Monitor is selected...or collect the various ones selected...
n = 0
If listContacts.SelectedIndex <> -1 Then
If listContacts.SelectionMode = ListSelectionMode.Single Then
txtCN.Text = listContacts.SelectedItem.Text
txtCID.Text = listContacts.SelectedItem.Value
Else
For i = listContacts.SelectedIndex To listContacts.Items.Count - 1
If listContacts.Items(i).Selected Then
n = n + 1
If n = 1 Then
s &= listContacts.Items(i).Text
r &= &quot;,&quot; & listContacts.Items(i).Value
Else
s &= &quot;, &quot; & listContacts.Items(i).Text
r &= &quot;, &quot; & listContacts.Items(i).Value
End If
End If
Next
txtCN.Text = s
txtCID.Text = r
End If
Else
lblContacts.text = &quot;Choose at least one Contact...&quot;
Exit Sub
End If
 
To process dynamically created controls, you must re-create them during load or init. They will then take the value of the associated control from the Viewstate (I know it seems odd to create new controls to get OLD values, but that's the way it works, I guess).

I'm doing something now where I collect input from N TextBoxes where N grows as the user gives more input. I'm stuffing size numbers into the Viewstate, then using their values to construct the appropriately-sized TextBox array on Load to enable property processing.
 
Boulder: sounds good. How about a post back when you're finished - would like to see the strategy. Thanks.
 
Here's the post back. I have something up and running that works, though I'm sure much of the process can be improved.

For a collection of N TextBoxes where N grows with additional user input, here's what I did.
[tt]
1. Declare a Table and ArrayList variable, both of which hold a collection of TextBox input controls. Also declare size variables in the Viewstate to keep track of just how large the structures are.

2. Go with the current algorithm:
a. on page load, construct a Table/ArrayList of
textboxes based on the size Viewstate variable.
-if the TextBox is on the end of the
Table/ArrayList then add a text changed
event listener to the control
-if the TextBox is the only TextBox on the
form, or it is not on the end, add a
required field validator to the control
-add a RegEx validator to the control either
way (guard against injection attack)
b. when the text of the end textbox changes,
increment the size Viewstate variable, and
post back to grow the inputs Table/ArrayList
c. when the &quot;process data&quot; button is pushed,
loop through all of the controls in the Table/
ArrayList doing what you will to them
[/tt]

In my case, I build a SQL statement using the dynamic front-end where multiple parameters can have either one or many values. I use an ArrayList of ArrayLists to keep track of the jagged matrix of inputs, and allow multiple parameters to grow dynamically.

When the user is done with the inputting, I do some text substitutions in some SQL statements stored in a database, then send the resulting string (as a session variable) to an Excel processor page to build a neatly-formatted spreadsheet of data for the user.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top