Image URL

Need help figuring this out

Page 1 of 1

6 Replies - 972 Views - Last Post: 24 June 2010 - 02:24 PM Rate Topic: -----

#1 Guest_CodeNewb*


Reputation:

Image URL

Posted 24 June 2010 - 10:26 AM

Hello all I have a program I am currently working on where a person selects an item from a dropdown list and an image control then displays an image related to that item.

Now heres the problem I am totally new at this and this is only the second time I've done image control (and the first time it is based on a dynamic drop down list).

The instructions are vague as all get out and only say "Add Code to the order page to display the image for the selected product in the Image Control. To do this you can set the ImageURL property of the image control to the location of the image file relative to the page appended with the ImageFile property of the Products object for the selected product. Note that this works because the ImageFile property contains a string with the name of the image file"

This is the code I have so far

<asp:Image ID="imgProduct" runat="server" AlternateText="Your Item" ImageUrl="/images/products/Order.aspx.ImageFile" ImageAlign ="Right"/>


I have no idea how to do what those directions say and they provide NO examples of a relative imageurl anywhere in the book so far.

How do I do what the directions say?

Is This A Good Question/Topic? 0

Replies To: Image URL

#2 Guest_CodeNewb*


Reputation:

Re: Image URL

Posted 24 June 2010 - 10:49 AM

Can anyone help?

I mean the book pretty much doesnt tell me anything on how to do what its telling me to do. And trying to search the net so far has proven fruitless.
Was This Post Helpful? 0

#3 Guest_Code_Newb*


Reputation:

Re: Image URL

Posted 24 June 2010 - 12:25 PM

I added the imgProduct.ImageUrl ="Images/Products/imgTemp"; to see if that would work but so far no joy.

If I do imgProduct.ImageUrl= "Images/Products/arm01.jpg"; it works and generates the arm01.jpg image from the Products folders list of pictures.

So how do I make it that the image file pics the .jpg file for the selected item?

if (!IsPostBack)
{
ddlProducts.DataBind();
selectedProduct = this.GetSelectedProduct();
lblName.Text = selectedProduct.Name;
lblShortDescription.Text = selectedProduct.ShortDescription;
lblLongDescription.Text = selectedProduct.LongDescription;
lblUnitPrice.Text = selectedProduct.UnitPrice.ToString("c");
string imgTemp= selectedProduct.ImageFile;
imgProduct.ImageUrl = "Images/Producs/imgTemp";

}
Was This Post Helpful? 0

#4 Magixion  Icon User is offline

  • D.I.C Addict



Reputation: 26
  • View blog
  • Posts: 634
  • Joined: 12-March 09

Re: Image URL

Posted 24 June 2010 - 02:08 PM

What is the value of selectedProduct.ImageFile? Is it simply like "arm01.jpg"?

If so, it should be really easy...

imgProduct.ImageUrl = "Images/Products/" + imgTemp;
Was This Post Helpful? 0
  • +
  • -

#5 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: Image URL

Posted 24 June 2010 - 02:21 PM

Your code will work if you place it in the right spot.

You should review the ASP.NET Page Life Cycle.


When the user selects an item in the DropDownList (and you have set it to autopostback to the server) then the DropDownList will post back to the server:

The Page Load event occurs
Then any event code is executed (In this case the SelectedIndexChanged event for the DropDownList)
Then the PreRender event occurs (then the render event and then the html is sent to the browser).

You should be setting the ImageUrl property for the image control in the SelectedIndexChanged event for the DropDownList.

-Frinny
Was This Post Helpful? 0
  • +
  • -

#6 Magixion  Icon User is offline

  • D.I.C Addict



Reputation: 26
  • View blog
  • Posts: 634
  • Joined: 12-March 09

Re: Image URL

Posted 24 June 2010 - 02:22 PM

Or just go with what Frinny says :P My ASP.NET is a bit rusty, hah.
Was This Post Helpful? 0
  • +
  • -

#7 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: Image URL

Posted 24 June 2010 - 02:24 PM

Oh common Magixion, give yourself credit.
My answer builds on your answer...you at least showed how to set the property!

-Frinny
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1