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

Change ImageButton visible property in code dynamically

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


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

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

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.