loop with field names

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everybody,

I want something like I used in MS Access:

for i = 1 to 20
me("FieldName" & i).Text = "Text bla bla bla"
next i

I want something like that because I have a series of fields like
FieldName1; FieldName2, FieldName3, ... which I want to fill in
programmaticaly.

thanks in advance

Filip
 
Filip,

What is the problem with that
I want something like I used in MS Access:

for i = 1 to 20
me("FieldName" & i).Text = "Text bla bla bla"
next i
\\\by instance roughly typed
for ctr in me.controls
dim number as integer = Cint(ctr.text.substring(9,0))
if number. > 0 AndAlso number < 21 then
ctr.text = "Text bla bla bla"
end if
Next
///
Did you know that there is a newsgroup
Microsoft.public.dotnet.languages.vb

There you can get a lot of methods for this (I took the most simple one)

Keep in mind that in dotNet windowforms every control can have his own
controlcollection, so when this is on a frame you have not to say "me",
however "frame1" or whatever.

I hope this helps?

Cor
 
Filip,

Was no message to tell you that this is the wrong forum, only to tell you
that there is in my opinon a better one than this for the question you had
and you want to know more of it.

Maybe I had answered that as well in that newsgroup, however there are more
who can answer the question than here

(Although before someone understand it wrong I am not the only one here who
can answer your question).

Cor
 
If these fields are really columns in a database, then you can effectively
still use the same technique, since the indexer on a dataset column is the
name of the field.

However, if these fields are actually variable names, you cannot do this
easily, and you may want to look at other schemes to index your values (like
an array).

Can you tell us if the "fields" are database columns or variables?

--- Nick
 
These fields are labels on the webform.
Sometimes i have 3 records of data, somtimes1, so I want to fill in the
labels by numbering them....
 
Filip De Backer said:
These fields are labels on the webform.
Sometimes i have 3 records of data, somtimes1, so I want to fill in the
labels by numbering them....

The easiest way is to have an array (or a map) of controls, rather than
have different actual fields.
 
Filip,

A webform needs a little different approach than a windowform, keep my
sample I showed you in the earlier message. However use as well an old
sample of my, to set the textboxes on a form to space. (When it is not
directly on a form however on a panel, it needs the approach which is the
same as in a windowsform)

I hope this helps?

Cor

\\\
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim frm As Control = Me.FindControl("Form1")
Dim ctl As Control
For Each ctl In frm.Controls
Dim tb As TextBox
If TypeOf ctl Is TextBox Then
tb = DirectCast(ctl, TextBox)
tb.Text = String.Empty
End If
Next
///
 
Back
Top