2

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

1
  • What does the value of dtrThumbnails[i]["ImageURL"] look like before you set it to the image url? Commented Aug 10, 2010 at 18:43

1 Answer 1

4

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.

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

1 Comment

10x so much!!!!!!!! :-)))))) milion smiles, i knew i needed the ~ but didn't know where and how to use it, and belive that i tried everything...well, allmost everything..lol....10x :-)

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.