Thursday, October 23, 2014

Change of Image control from static to dynamic


I am having 6 Image controls which get the images from the folder through URL in the database. The point is that i am doing it statically. I want to change it over to dynamic by using for loop or for each loop but i am not getting an idea how to do it. In future if the number image controls increases so it is hard to specify each an every one statically.


I am using asp Image tag.


so far the code works fine as static but i want it make it dynamic using some loop.


code which i have tried so far:



protected void Page_Load(object sender, EventArgs e)
{
using
(Property_dbDataContext context = new Property_dbDataContext())
{
var strURL = context.retrieveImage()
.Select(s => s.image_url)
.ToList();

Image1.ImageUrl = strURL[0];
Image2.ImageUrl = strURL[1];
Image3.ImageUrl = strURL[2];
Image4.ImageUrl = strURL[3];
Image5.ImageUrl = strURL[4];
Image6.ImageUrl = strURL[5];
}
}



No comments:

Post a Comment