473,509 Members | 2,918 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change ImageButton visible property in code dynamically

I am tring to loop through a dataset to find records that exist. If the
record exists then make the corresponding image visible. So I try to take
the row value and concatenate it onto a string ("imgSession"), so the
resulting control ID name will be imgSessionX. Where X could be a number
corresponding to the ID of the image. I need help with the logic.

Dim row As DataRow

Dim myImage As Image

Dim imgName As String = "imgSession"

For Each row In ds.Tables(0).Rows

'something like the below code, I realize this doesn't work

imgName = "imgSession" & row(0)

myImage.ID = imgName

myImage.Visible = True

Next

Not suprisingly I am getting the error "Object reference not set to an
instance of an object."

Thanks!
Nov 19 '05 #1
4 2596
The subject line should read "Change Image visible property in code
dynamically" not ImageButton.

I could use a big Case statement but would rather not.

Select Case row(0)
Case 13
imgSession13.Visible = True
Case 14
imgSession14.Visible = True
End Select

Hopefully this helps out


"Andy G" <aj*****@iastate.edu> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
I am tring to loop through a dataset to find records that exist. If the
record exists then make the corresponding image visible. So I try to take
the row value and concatenate it onto a string ("imgSession"), so the
resulting control ID name will be imgSessionX. Where X could be a number
corresponding to the ID of the image. I need help with the logic.

Dim row As DataRow

Dim myImage As Image

Dim imgName As String = "imgSession"

For Each row In ds.Tables(0).Rows

'something like the below code, I realize this doesn't work

imgName = "imgSession" & row(0)

myImage.ID = imgName

myImage.Visible = True

Next

Not suprisingly I am getting the error "Object reference not set to an
instance of an object."

Thanks!

Nov 19 '05 #2
Call the FindControl method with the name of the control you want.

"Andy G" <aj*****@iastate.edu> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
I am tring to loop through a dataset to find records that exist. If the
record exists then make the corresponding image visible. So I try to take
the row value and concatenate it onto a string ("imgSession"), so the
resulting control ID name will be imgSessionX. Where X could be a number
corresponding to the ID of the image. I need help with the logic.

Dim row As DataRow

Dim myImage As Image

Dim imgName As String = "imgSession"

For Each row In ds.Tables(0).Rows

'something like the below code, I realize this doesn't work

imgName = "imgSession" & row(0)

myImage.ID = imgName

myImage.Visible = True

Next

Not suprisingly I am getting the error "Object reference not set to an
instance of an object."

Thanks!

Nov 19 '05 #3
I don't think that will help. What I need to do is:

imgSession & [number that I got from the query].Visible = True so it would
look like the following if 13 was the number that was returned.
imgSession13.Visible = True

"Marina" <so*****@nospam.com> wrote in message
news:Or*************@TK2MSFTNGP12.phx.gbl...
Call the FindControl method with the name of the control you want.

"Andy G" <aj*****@iastate.edu> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
I am tring to loop through a dataset to find records that exist. If the
record exists then make the corresponding image visible. So I try to take
the row value and concatenate it onto a string ("imgSession"), so the
resulting control ID name will be imgSessionX. Where X could be a number
corresponding to the ID of the image. I need help with the logic.

Dim row As DataRow

Dim myImage As Image

Dim imgName As String = "imgSession"

For Each row In ds.Tables(0).Rows

'something like the below code, I realize this doesn't work

imgName = "imgSession" & row(0)

myImage.ID = imgName

myImage.Visible = True

Next

Not suprisingly I am getting the error "Object reference not set to an
instance of an object."

Thanks!


Nov 19 '05 #4
The dataset will be displayed in a datagrid, correct?
In the ItemDataBound event handler check the viability of the database
record. If no, set the Image for that row to be invisible.

"Andy G" <aj*****@iastate.edu> wrote in message
news:eo**************@TK2MSFTNGP12.phx.gbl...
I am tring to loop through a dataset to find records that exist. If the
record exists then make the corresponding image visible. So I try to take
the row value and concatenate it onto a string ("imgSession"), so the
resulting control ID name will be imgSessionX. Where X could be a number
corresponding to the ID of the image. I need help with the logic.

Dim row As DataRow

Dim myImage As Image

Dim imgName As String = "imgSession"

For Each row In ds.Tables(0).Rows

'something like the below code, I realize this doesn't work

imgName = "imgSession" & row(0)

myImage.ID = imgName

myImage.Visible = True

Next

Not suprisingly I am getting the error "Object reference not set to an
instance of an object."

Thanks!

Nov 19 '05 #5

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

Similar topics

2
374
by: Nate | last post by:
I am trying to set the Enabled property of an ImageButton on a web form. I would like to programmatically Enable and disable the image Button from code behind using C#.
1
3021
by: JIM | last post by:
Hello, Does anyone knows how to set the visible property of an asp:Imagebutton to true with javascript I've the following declared : <asp:ImageButton Id="tstImage" runat="server"...
3
5151
by: JIM | last post by:
Hello, I've an asp:Imagebutton on my form with the visible property set to false <asp:Imagebutton ID="tstImage" runat=Server visible=False> How can I set the visible propery to true using a...
3
3901
by: jens.buchta | last post by:
Hi! I'm using a DataGrid with a template column to display an Image inside of it. I'm hooking into its OnPrerender-Event to set the ImageURL-Property dynamically. Everything works just fine...
2
10278
by: sck10 | last post by:
Hello, I am trying to programically make the following TemplateField ("MyTemplate") visible when the user clicks on the "Edit" Button using the PreRender handle event. My question is, how do...
1
1167
by: akis | last post by:
Hello, I have a loop e.g. for(i=0;i<10;i++) { ib = new ImageButton(); } and all i want is to know which imagebutton the user clicked and populate a textbox
0
1096
by: Marc Robitaille | last post by:
Hello everyone, I have a control which inherits from another control. I added a contextual menu to the new control. To this new control, I added a Boolean property. This property enables me to...
1
2867
by: fabrice | last post by:
Hello, I d like to modify the Onclik Event of an ImageButton control in code behind. But when i do it , i get an error. This is ma code : The control is the pasx page :
1
2916
by: Cem | last post by:
Hi, in GridView1 I have following code: <ItemTemplate> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# Eval("airport_active", "images/icons/ico_airport_active_{0}.gif") %>'...
0
7237
marktang
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,...
0
7347
Oralloy
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,...
1
7073
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...
0
7506
tracyyun
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...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
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 ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.