954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using a Label Text to display an image dynamically

Hi all, I am kinda new to the area so please bear with me :)

I want to dynamically display an image according to a certain variable obtained from an XML document and I did the following code where intTypeID is a variable whose value changes according to the nodes being read:

// Choose which image to show
                switch (intTypeID)
                {
                    case 1:
                        strNewsImage = "<asp:Image \"ID=imgGeneral\" runat=\"server\" ImageUrl=\"~/images/news_general.gif\" />";
                        break;
                    case 2:
                        strNewsImage = "<asp:Image \"ID=imgEvent\" runat=\"server\" ImageUrl=\"~/images/news_event.gif\" />";
                        break;
                    default:
                        strNewsImage = "<asp:Image \"ID=imgGeneral\" runat=\"server\" ImageUrl=\"~/images/news_general.gif\" />";
                        break;
                }


However the images are not displaying...any idea as to why? I am sure that the code is correct as when I copy it in the .aspx part it displays correctly. Can you please help me :)

Thanks
Darren

dmizz002
Newbie Poster
4 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

Use tags.

switch (intTypeID)
                {
                    case 1:
                        strNewsImage = "<img  src='images/news_general.gif' alt='' />";
                        break;
                    ....
                }
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: