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?
Image URLNeed help figuring this out
Page 1 of 1
6 Replies - 770 Views - Last Post: 24 June 2010 - 02:24 PM
Replies To: Image URL
#2 Guest_CodeNewb*
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.
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.
#3 Guest_Code_Newb*
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";
}
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";
}
#4
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;
If so, it should be really easy...
imgProduct.ImageUrl = "Images/Products/" + imgTemp;
#5
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
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
#6
Re: Image URL
Posted 24 June 2010 - 02:22 PM
Or just go with what Frinny says
My ASP.NET is a bit rusty, hah.
#7
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
My answer builds on your answer...you at least showed how to set the property!
-Frinny
Page 1 of 1
|
|

New Topic/Question
Reply
MultiQuote








|