Reputation: 1953
I'm using a UC to create a generic Thumb display.
My UC located in: UserControls folder and my images are in: Images folder.
Every record in the DB had a ImageUrl path that go to: Images/Items/(fileName).
My problem is that for every file (I think that durring rendering the folder name (UserControls) is added so in the source i get the following line:
<img src="UserControls/Images/Items/1t.jpg" style="border-width:0px;" /></td>
I really need to be able to remove the "UserControls/" from the code but nothing works (i've tried remove() and every thing, but the problem is that the folder UserControl is added durring rendering or what ever, i've checked the ImageUrl and it is good all the way even after i push it to the tableRow and so on....
I know it happen becouse of the project hierarchy of the folders, but unfortunatily, changing that is not an option...
Here is my code, if any one has any idea it would be great, 10x
if (dtrThumbnails.Length > 0)
{
for (int i = 0; i < dtrThumbnails.Length; i++)
{
TableCell tdImgThumb = new TableCell();
Image ImgThumb = new Image();
ImgThumb.ImageUrl = dtrThumbnails[i]["ImageURL"].ToString();
tdImgThumb.Controls.Add(ImgThumb);
trImageThumbs.Controls.Add(tdImgThumb);
ImgThumb.Dispose();
RadioButtonList rdoImgList = new RadioButtonList();
TableCell tdImgChecked = new TableCell();
RadioButton rdoImgCheck = new RadioButton();
rdoImgCheck.ID = dtrThumbnails[i]["ImageID"].ToString();
rdoImgCheck.GroupName = "ImgThumbs";
if (Convert.ToInt16(dtrThumbnails[i]["ImageID"]) == _CurrentThumb)
rdoImgCheck.Checked = true;
tdImgChecked.Controls.Add(rdoImgCheck);
trImageCheck.Controls.Add(tdImgChecked);
rdoImgCheck.Dispose();
}
}
dtrThumbnails is a DataRow[] that holds all the records.
10x again
Upvotes: 2
Views: 473
Reputation: 2481
Change this line:
ImgThumb.ImageUrl = dtrThumbnails[i]["ImageURL"].ToString();
To this:
ImgThumb.ImageUrl = "~/" + dtrThumbnails[i]["ImageURL"].ToString();
The ~/ tells the Url field on controls (including the ImageUrl field on an Image control) to go to the root of the application and append the rest of the path there.
You could also just append "/" but if your site is not at the root of the domain, that will cause problems.
Upvotes: 4