By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,186 Members | 1,551 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,186 IT Pros & Developers. It's quick & easy.

iterate through a set of controls

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
"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.