473,385 Members | 1,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

array of textboxes

I'm wondering if there's a way to create an array of textboxes, or loop
through textboxes. The textboxes are in an ASP.NET page, but the
looping happens through Visual Basic.
On page load, textboxes are dynamically created like this:

While Not rs.eof
Response.Write("<tr><td><input type='text' name='article'" &
numberOfRows & "' value='0'></td></tr>")
numberOfRows += 1
rs.movenext()
End While
Next, when you hit a button ("Order"), I want to check which of these
textboxes has a value different than 0.
The goal is to allow people to order a certain number of items (a
simple webshop, basically).
A possible way to do this:

Dim i As Integer, txt As String
For i = 0 To numberOfRows
txt = "article" & i
If txt.value <> "0" Then
Session.Contents("product" & i) = txt.value
End If
Next

So I want to check for each textbox if it contains the value '0', and,
if not, add the number of items you want to a session variable. Of
course, I still need to assign the article code of it too, but that's
for afterwards (unless someone's got a suggestion...). As you can
guess, it doesn't work at all like this. So in this newsgroup I
found something like this:

For Each ctl As Control In Page.Controls
If TypeOf (ctl) Is TextBox And ctl.ID <> "txtaccount" And ctl.ID <>
"txtpaswoord" Then
If ctl <> "0" Then
session.contents(ctl.id) = ctl.value
End If
End If
Next

However, ctl.value etc. doesn't work, either. If anyone has an idea,
please tell. I don't have any idea how to do arrays in asp.net though,
as my knowledge of it is still very limited, so please don't use too
difficult explanations.

Thanks a lot!

Nov 19 '05 #1
3 2921
HI Samneefs:

On 5 Mar 2005 05:43:29 -0800, sa******@gmail.com wrote:

For Each ctl As Control In Page.Controls
If TypeOf (ctl) Is TextBox And ctl.ID <> "txtaccount" And ctl.ID <>
"txtpaswoord" Then
If ctl <> "0" Then
session.contents(ctl.id) = ctl.value
End If
End If
Next


If you coherce the control object into being a TextBox type, then you
can get the Text property directly. First check to see if the control
is a TextBox (If TypeOf Ctl Is TextBox), and use DirectCast to change
the type to TextBox.

Note: you will need to check the Controls property of each control if
the TextBox controls are nested.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

Nov 19 '05 #2
Many thanks for your help.
I've looked up the DirectCast function in MSDN, and tried to apply it
(to be honest I don't really understand it completely, mostly why I
need to put a variable before it (as in dim a as b = DirectCast(c,d)).

What I've got now looks like this:

For Each ctl As Control In Page.Controls
If TypeOf (ctl) Is TextBox And ctl.ID <> "txtaccount" And ctl.ID <>
"txtpaswoord" Then
'txtaccount & txtpaswoord are not part of the textboxes we want to
check for values

Dim txt As TextBox = DirectCast(ctl, TextBox)
If txt.Text <> "0" Then
'Session.Contents(txt.ID) = txt.Text
'aantalSessionVariables += aantalSessionVariables

Me.cmdBestellen.Text = "ok"
End If
End If
Next

I wanted to change the caption of cmdBestellen (meaning
cmdPlaceYourOrder in English) to see if it worked, but it didn't (the
caption didn't change).
Any suggestion to what could be wrong?

(Also, do you (or anyone else) know if it's possible to create an array
of session variables? I'd like to assign both the id and the value of a
textbox in an array's "row", if possible).

Many thanks for your suggestions, it's greatly appreciated!

Nov 19 '05 #3
I suspect Page.Controls only holds the form control, and the textboxes
are another level lower (in Page.Controls(0).Controls). You'll have to
keep moving down the control hierarchy - know what I mean?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 5 Mar 2005 07:36:16 -0800, sa******@gmail.com wrote:
Many thanks for your help.
I've looked up the DirectCast function in MSDN, and tried to apply it
(to be honest I don't really understand it completely, mostly why I
need to put a variable before it (as in dim a as b = DirectCast(c,d)).

What I've got now looks like this:

For Each ctl As Control In Page.Controls
If TypeOf (ctl) Is TextBox And ctl.ID <> "txtaccount" And ctl.ID <>
"txtpaswoord" Then
'txtaccount & txtpaswoord are not part of the textboxes we want to
check for values

Dim txt As TextBox = DirectCast(ctl, TextBox)
If txt.Text <> "0" Then
'Session.Contents(txt.ID) = txt.Text
'aantalSessionVariables += aantalSessionVariables

Me.cmdBestellen.Text = "ok"
End If
End If
Next

I wanted to change the caption of cmdBestellen (meaning
cmdPlaceYourOrder in English) to see if it worked, but it didn't (the
caption didn't change).
Any suggestion to what could be wrong?

(Also, do you (or anyone else) know if it's possible to create an array
of session variables? I'd like to assign both the id and the value of a
textbox in an array's "row", if possible).

Many thanks for your suggestions, it's greatly appreciated!


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Bhavin | last post by:
Anybody quickly replies it, would be a great help! I try to create dynamic array of textboxes control in ASP.NET(C#). I got the following error while I tried to assign value to ID property of...
2
by: RBohannon | last post by:
Is it possible to create a control array on an unbound form? I would like to be able to loop through a series of unbound text boxes. Thanks.
1
by: Stephen | last post by:
Was wondering if someone could please help me with an array I'd like to create in an asp.net page. I have to design an array which stores the values of addresses manually entered into textboxes...
10
by: Altman | last post by:
In vb 6 you use to be able to create an array of objects and I can't seem to figure this out in .NET. I figured you can't make this but I was wondering how I could do it if I had for instance 3...
3
by: barbara | last post by:
Hi all, I need to use hundreds of textboxes to display data. In VB 6.0, I can assign the value by the loop with a textboxes array. How to do it in VB.net? Thanks a lot.
6
by: Rich | last post by:
Hello, I have an application that contains several checkboxes. I originally created this app in VB.Net 2003 and upgraded the app to VB.Net 2005. I understand the vb2005 supports control...
9
by: jan82 | last post by:
Hi everybody I declared a private static array of textboxes at the top of a class, then i generate the array elements (new textbox()) in a separate function (private void in the same class), ...
1
by: bethmiddy | last post by:
Hello, I am very new to programming and am currently taking a class on VB. This is probably very simple, I just don't get it. I am working on a group project where we need to have 3 columns and...
7
by: Angel López | last post by:
How to do this with Vb.net 2008??? myNumber=1+ Int(Rnd()*90) text(myNumber).backcolor=vbRed Tanks Angel
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.