469,270 Members | 1,717 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

iterate through a set of controls

Hi

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 ?

thanks

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

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

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #2
"romy" <ro******@Powerup1.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
Romy,

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

I hope this helps,

Cor
Nov 21 '05 #4
"romy" <ro******@Powerup1.com> wrote in message
news:uz**************@TK2MSFTNGP12.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"
Next

HTH,
Phill W.
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tina | last post: by
reply views Thread by Rob Meade | last post: by
2 posts views Thread by Luqman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.