Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Refering to the label names with a variable
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows XP
Database:
MS SQL Server
Divers
Thread ID:
01303041
Message ID:
01303082
Vues:
9
>Hi,
>
>If its not possible to refere to the label names with a variable. For example - Something like labeli.text = "something", then increment i by 1 and then repeat the statement - only this time labeli now becomes label2.
>
>Is there any other way i can create mutiple labels, drop down, textboxes in runtime depending on dynamic array's output and then assign all the text values of each control with a loop instead of coding them all out individually.
>
>
>Thanks for the help.
>
>Bilal.

You can instanciate an instance of a single control, set it's properties, then add that control to the form's Controls collection.
While index < 10
   Dim lblDynamic As Label = New Label()
   lblDynamic.Text = index.ToString()
   Me.Controls.Add(lblDynamic)
   index += 1
End While
You'd probably have to do this in the Page_Init. You also have to make sure you recreate the same exact controls on each page postback in order for events to fire and viewstate (if you're using it) to work correctly.

While you might get this to work, I'd think long and hard about doing it - it's easy to get this wrong and have weird errors that are hard to diagnose and/or fix.

You might be able to do what you're looking for by using something like the Repeater control.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform