Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have one master page in which i have taken one image control in which i want to show single image from database url according to content page.. i have two columns in database imageurl and pagename. and images are in a folder images.. i have no idea how to do this becauese image control does not have data source property.
Posted

In code, you have to fetch the image URL from the database and assign it to the ImageUrl property of the Image control.
 
Share this answer
 
image control does not have data source property.
But, image does have a 'source' property.

Steps:
1. From database, query the image path based on the path. Query could be like:
SQL
SELECT imageURL FROM myTable WHERE pagename=@currentContentPage

2. Based on the imageURL returned, you need to access it and then use this as a image source. Something like:
C#
myImage.ImageUrl = dataTableFetched.Tables[0].Rows[0][imageURL].ToString();
//if it was absolute path to the server folder then it will work 
//or else first you need to format iinto correct url and then assign to imageURL


You need to check for validations and null as per need.

Try!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900