If I have 10 imagebuttons on a form (imagebutton1, imagebutton2,
imagebutton3, etc.) in asp.net and I want to loop through each one and set
their imageurl in a loop how can this be done.
Something like :
dim i as int16
for i = 1 to 10
imagebutton(i).imageurl="whatever.jpg"
next
The code above does not work... is it possible to do this?
Thanks.dim ctl as Control
for each ctl in me.controls
if typeof ctl is imageButton
ctype(ctl, imageButton).imageurl = "whatever.jpg"
end if
next
"Jay" <msnews.microsoft.com> wrote in message
news:OQNCa4vhDHA.1180@.TK2MSFTNGP12.phx.gbl...
> If I have 10 imagebuttons on a form (imagebutton1, imagebutton2,
> imagebutton3, etc.) in asp.net and I want to loop through each one and set
> their imageurl in a loop how can this be done.
> Something like :
> dim i as int16
> for i = 1 to 10
> imagebutton(i).imageurl="whatever.jpg"
> next
> The code above does not work... is it possible to do this?
> Thanks.
check out this article for looping through controls,
http://www.extremeexperts.com/Net/A...ghControls.aspx
--
Saravana
Microsoft India Community Star,MC**
www.extremeexperts.com
"Jay" <msnews.microsoft.com> wrote in message
news:OQNCa4vhDHA.1180@.TK2MSFTNGP12.phx.gbl...
> If I have 10 imagebuttons on a form (imagebutton1, imagebutton2,
> imagebutton3, etc.) in asp.net and I want to loop through each one and set
> their imageurl in a loop how can this be done.
> Something like :
> dim i as int16
> for i = 1 to 10
> imagebutton(i).imageurl="whatever.jpg"
> next
> The code above does not work... is it possible to do this?
> Thanks.
Thanks a lot. But what if I only wanted to set the imageurl for
imagebutton1, 2, 3 - 10? If there were other imagebuttons on the page they
would be set as well.
"Srinivas Kotipalli" <srinivask@.sbcglobal.net> wrote in message
news:ORT0b#vhDHA.1964@.TK2MSFTNGP10.phx.gbl...
> dim ctl as Control
> for each ctl in me.controls
> if typeof ctl is imageButton
> ctype(ctl, imageButton).imageurl = "whatever.jpg"
> end if
> next
> "Jay" <msnews.microsoft.com> wrote in message
> news:OQNCa4vhDHA.1180@.TK2MSFTNGP12.phx.gbl...
> > If I have 10 imagebuttons on a form (imagebutton1, imagebutton2,
> > imagebutton3, etc.) in asp.net and I want to loop through each one and
set
> > their imageurl in a loop how can this be done.
> > Something like :
> > dim i as int16
> > for i = 1 to 10
> > imagebutton(i).imageurl="whatever.jpg"
> > next
> > The code above does not work... is it possible to do this?
> > Thanks.
use a consistent naming convention for the image controls (e.g. image1,
image2 etc)
then something like
dim x as int16
dim ctrlname as string
dim img as Control
for x=1 to 10 ' or whatever
ctrlname="image" & x
img=FindControl(ctrlname) ' find name control
img.imageurl="someimage.jpg"
next
Hope that helps
Roger
"Jay" <msnews.microsoft.com> wrote in message
news:#4Nj0l0hDHA.1964@.TK2MSFTNGP10.phx.gbl...
> Thanks a lot. But what if I only wanted to set the imageurl for
> imagebutton1, 2, 3 - 10? If there were other imagebuttons on the page
they
> would be set as well.
>
> "Srinivas Kotipalli" <srinivask@.sbcglobal.net> wrote in message
> news:ORT0b#vhDHA.1964@.TK2MSFTNGP10.phx.gbl...
> > dim ctl as Control
> > for each ctl in me.controls
> > if typeof ctl is imageButton
> > ctype(ctl, imageButton).imageurl = "whatever.jpg"
> > end if
> > next
> > "Jay" <msnews.microsoft.com> wrote in message
> > news:OQNCa4vhDHA.1180@.TK2MSFTNGP12.phx.gbl...
> > > If I have 10 imagebuttons on a form (imagebutton1, imagebutton2,
> > > imagebutton3, etc.) in asp.net and I want to loop through each one and
> set
> > > their imageurl in a loop how can this be done.
> > > > Something like :
> > > > dim i as int16
> > > for i = 1 to 10
> > > imagebutton(i).imageurl="whatever.jpg"
> > > next
> > > > The code above does not work... is it possible to do this?
> > > > Thanks.
> >
'This worked for me on a series of textboxes named
'txtPartnumber1 through txtPartnumber10 :
Dim ctlname As String
Dim ctltextbox As Control
For x = 1 To 10
ctlname = "txtPartnumber" & x
ctltextbox = FindControl(ctlname)
CType(ctltextbox, TextBox).Text = "1234567"
Next
Monday, March 26, 2012
Loop through controls??
Labels:
asp,
controls,
form,
imagebutton1,
imagebutton2,
imagebutton3,
imagebuttons,
loop,
net,
settheir
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment