1

I am trying to show image on the label retrieved from the database. My front end code is

<asp:Image ID="Image1" runat="server" Height="150px" Width="120px" />

where as my backend code is:

  string query = "select quantity, name, price, description, type, Catagory, FilePath from product where p_id ='" + IdList.SelectedValue + "'  ";
            con.Open();
            SqlCommand cmd = new SqlCommand(query, con);
            SqlDataReader rdr = cmd.ExecuteReader();

            if(rdr.HasRows)
            {
                while (rdr.Read())
                {  string filename1 = rdr.GetString(6);
                    Image1.ImageUrl="C:\\Users\\Fatima\\Downloads\\db-final-project\\db final project\\db final project\\UploadedImages\\"+filename1; }

kindly help me in displaying my image in label in the web form

2
  • what is the value of filename1 ? Commented May 26, 2016 at 7:36
  • its the name of image retrieved from database Commented May 26, 2016 at 7:41

1 Answer 1

1

"C:\Users\Fatima\Downloads\db-final-project\db final project\db final project\UploadedImages\" is not a valid URL. Image1.ImageUrl expects a URL, like "http://www.SomeSite.com/someImage.jpg", and not a local directory on your hard-drive.

Put those pictures in your database (there should be a table column of type 'image' which can store images) or better yet - add it as an asset to your project and link to its relative path (e.g., the path in which your site/application resides in, without the domain name).

You can see a valid usage of Image.ImageUrl in here: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.image.imageurl.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.