ImageURL setting

  • Thread starter Thread starter pvong
  • Start date Start date
P

pvong

I'm trying to programmically set the location my image control. How do you
set it? The file is under an Image folder under the root directory of the
web folder.

I'm doing this in VB.NET and I'm trying to set this in RowDataBound. I'm
getting the error msg of: Object reference not set to an instance of an
object.

Below is my code:
 
Thanks for responding. I'm definitely a newbie. After getting your reply,
I realized how I could fix this but I'm not sure why it work. Below is my
code and it works fine. Can you tell me why I didn't have to use the Cell
count for this to work in my scenrio?
Dim pix As Image = CType(e.Row.FindControl("StatusI"), Image)

If e.Row.RowType = DataControlRowType.DataRow Then

pix.ImageUrl = "~\images\cryingface.gif"
 
Phillip,

Find control iterates through the row and the cells looking for the object
you specify. It can be very useful that it does so, but it's also an
intensive operation. Your applications will run faster if you limit your use
of find control and whenever possible refer to the objects you need directly
by giving the exact index of the object in question. Of course referring to
objects directly by figuring out their exact index is sometimes difficult.
And if you ever add a column you have to go into the code and re-index
everything which can be a pain.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
Back
Top