473,734 Members | 6,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

iterate through a set of controls


In VB.net

I have a set of linkButtons controls in a form , which I want to iterate on
them and change their text property.

How it's done ?


Nov 21 '05 #1
4 6587
Dim c As Control

For Each c In Me.Controls
If TypeOf c Is LinkButton Then
c.Text = "Bla Bla"
End If
Next c

Nov 21 '05 #2
"romy" <ro******@Power up1.com> schrieb:
I have a set of linkButtons controls in a form , which I want to iterate
on them and change their text property.

Web Forms or Windows Forms?

M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

Dim frm As Control = Me.FindControl( "Form1")
For Each ctl as Control In frm.Controls
if TypeOf ctl Is Linkbutton Then
DirectCast(ctl, Linkbutton).Tex t = "WathEver"
End If

I hope this helps,

Nov 21 '05 #4
"romy" <ro******@Power up1.com> wrote in message
news:uz******** ******@TK2MSFTN GP12.phx.gbl...
I have a set of linkButtons controls in a form, which I want to
iterate on them and change their text property.

You /could/ loop through the Controls collection of the Form,
looking for LinkButtons. Sadly, this /only/ works when all the
LinkButtons are actually placed /on/ the Form and not inside
any "container" controls, like Panels or GroupBoxes, in which
case you have to [recursively] scan the Controls Collection of
each container!

Alternatively, if the LinkButtons are all set up at Design Time,
create a - gasp - Control Array. No, don't laugh; I actually
mean an Array of Controls or, in this case, of LinkButtons, as in

Private AllLinkButtons as LinkButton() = { _
Me.LinkButton1, Me.LinkButton2, Me.LinkButton3

Then, you can simply use

For Each eLB as LinkButton in AllLinkButtons
eLB.Text = "whatever"

Phill W.
Nov 21 '05 #5

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

Similar topics

by: Simon | last post by:
I've got a webform and many controls on it. I would like to iterate thru the control collection to get all the textboxes control to let me change the text property. Here is my code...for unknown reason, this loop iterates only 3 times! Help please! Thanks! Dim Control As Web.UI.Control Dim TextBox As System.Web.UI.WebControls.TextBox For Each Control In Controls If TypeOf (Control) Is System.Web.UI.WebControls.TextBox Then
by: James Doran | last post by:
Hello, I'd like to iterate through each Page of my ASP.NET project from within a Custom web control and access the Page.Controls collection. I've tried using Reflection on the web project assembly, but the controls collection count was zero. While this method gives details of the private controls in each page, I need access to actual instances of the controls to interrogate their individual properties.
by: Tina | last post by:
I need to find all of the datagrids on a page. How can I iterate through all of the controls on a page to get their name and grab them as an object? thanks, T
by: Oleg | last post by:
Let's say I rendered a bunch of controls with the same name and different IDs. On postback, can I somehow iterate through these controls (checkboxes in this case, but could be dropdown controls in the future) and get their values and IDs with all this done in the code behind page? A small example would be appreciated. Thanks, Oleg
by: Rich | last post by:
Hello, I have a form with 5 textboxes named txt0, txt1, txt2, txt3, tx4. In VB6 I could iterate through these with For i = 0 to 4 debug.print Me.controls("txt" & i).Name Next
by: A | last post by:
HI all, I am trying to iterate over all the controls on my form and if a control IS A textbox then I want to enter the If statement. So far I can't get it to work...here is the code...any help? For Each c As Control In Me.Controls
by: Rob Meade | last post by:
Hi all, I have a page, where, because it had to all be in one page there are a multitude of panels, with the use of a handful of conditions and the ability to show/hide panels I am able to make this page look like the user is moving between many... Here's my problem... I started off by simply seting the visibility to true/false etc in each code
Shashi Sadasivan
by: Shashi Sadasivan | last post by:
In my current application, I have to set cettain defaults to controls that are displayed or are used. so i have a class to which i send the form as a control, and iterate through each of its controls and child controls However, I have to also edit the Interval property of any timers present in the form. Timers come under the Windows.Forms.Timer namespace and i am currently iterating through all the Controls in the form. How would I...
by: Luqman | last post by:
I have a Ajax Tab Container on my Webform with One Panel and some Labels and Textboxes. I want to Iterate through all the textboxes and return their IDs. I tried every possibility I could but I was unable to retrieve their IDs. Here is my code, which returns nothing. Dim ctrl as new Control
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.