Change ImageButton visible property in code dynamically

A

Andy G

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!
 
A

Andy G

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
 
A

Andy G

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
 
C

C.F.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top