How do I group the TextBox controls and get their values in codebehind pages?

L

Learner

Hi there,
I have 10 text boxes defined to insert their values into the database.


How do I group all of these text boxes? I mean provide a common name to
the group and try access the values in the code behind page using For I
= 1 to 10 Next loop.

For instance the text boxes I have now are as below

_txtOptionText1
_txtOptionText2
_txtOptionText3
....
_txtOptionText10

I don't know of any property so that I can group them and access the
group in the code behind page.

Any input is appriciated,
-L
 
L

Learner

Hello Jeff,
I am sorry I don't understand what you are trying to explain. Could you
please take another moment to explain it a little.
Thanks,
-L
 
O

o0JoeCool0o

how about

dim myControl as string
dim i as integer
dim currentTextBox as textbox
mycontrol="txtOptionText"

for i = 1 to 10
currentTextBox = page.FindControl(myControl & i)
currentTextBox.text = "Value " & i
next i
 
J

Jeff Dillon

Did you try it? I'm just suggesting, create your own attribute. Essentially
your own property.

Jeff
 
L

Learner

Hello Friends,
This is how finally I got it working :) . We use Master pages in our
application so I had to use FindControl to find the contentplaceholder
and then the controls inside of it. Its cool.

Dim QuestinOptionInsertResult As String = String.Empty
Dim myControl As String
Dim i As Integer
Dim currentTextBox As TextBox
myControl = "_txtOptionText"
Dim ctntplaceHolder As ContentPlaceHolder
ctntplaceHolder =
CType(Page.Master.FindControl("_ContentHolder"), ContentPlaceHolder)
For i = 1 To 5
currentTextBox = ctntplaceHolder.FindControl(myControl
& i)
Dim myCurrentTextBoxValue = currentTextBox.Text
If myCurrentTextBoxValue <> "" Then
Dim QuestionID As Integer =
Convert.ToInt32(GetBL.GetQuestionID())
QuestinOptionInsertResult =
GetBL.InsertQuestionOptions(QuestionID, _

myCurrentTextBoxValue, _

InsertedBY, _

ModifiedBy)
End If
Next i
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top