using a variable to display the number of images

Hello All

I am not sure if this is the right forum or not so, my apologies before hand if I am guilty. I have a ASP.Net 1.1 C# application that has a property retrieving value (int) from my database. I would like to use this value as the number of images to dispaly in the page. I have two images (image1.gif and Image2.gif) in my  \image folder on my file system. If the property value(int) is zero(0) image1.gif will be displayed; if the property value(int) is 1 or greater, image2.gif will be displayed the number of times the value is equal to. For clarification if the value is 3, three image2.gif files will be displayed on the page. I am not sure if I should use javascipt for this or if ASP.net can handle this. An example would be helpful. Need urgent help!  I hope I was clear about my requirements.

Thanks In Advance for you help on this.
kw_uh97Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZvonkoSystems architectCommented:
It is better to do it on C# side.

0
kw_uh97Author Commented:
Thanks Zvonko:

But how would I go about doing it on the C# side. I am already getting the value how will I display which and how many image(s) shows up in the HTML.

Thanks In Advance.
0
ZvonkoSystems architectCommented:
Perhaps like this:

  string noneImg =  "/images/image1.gif";
  string oneImg = "/images/image2.gif";

    conn = new SqlConnection(ConnectionString());
   /// cmd = new SQL...

   if(result.Count > 0){
    for(int i=1;i<=result.Count;i++){
       output("<img src='" + oneImg +"' >");
    }
  } else {
       output("<img src='" + noneImg +"' >");
 }



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

kw_uh97Author Commented:
I am getting "The name 'output' does not exist in the class or namespace " whenever I attempt to build the solution. Do I have to have using class statement and if so which class?

Thanks in advance
0
ZvonkoSystems architectCommented:
Oh, sh!t
Now I see I am in C# topic area :)
I have no idea how C# works, sorry.

And if you also do not know how output works in C#, then perhaps you should start learning C# ;-)

0
kw_uh97Author Commented:
Well I guess you exposed me. I am learning C#; I am a novice. Sorry don't beat me too bad.
0
ZvonkoSystems architectCommented:
I am not even a Novice :-)

What I have grabbed around is that there is some System.out.writeln() method or so. But you have for sure more acurate examples around. Anyway, C# is something that I for sure will lern (when I get time :)

Perhaps like this:

            protected override void Render(HtmlTextWriter output)
            {
                  try
                  {
                        string OutPut = "";
                        string noneImg =  "/images/image1.gif";
                        string oneImg = "/images/image2.gif";

                        conn = new SqlConnection(ConnectionString());
                        /// cmd = new SQL...

                        if(result.Count > 0){
                          for(int i=1;i<=result.Count;i++){
                            OutPut = OutPut +"<img src='" + oneImg +"' >";
                          }
                         } else {
                            OutPut = OutPut  + "<img src='" + noneImg +"' >";
                          }
                          output.Write(OutPut);
                  }

                  catch(Exception ex)
                  {
                        output.Write("Errror building List:<br>");
                        output.Write(ex.InnerException);
                  }
            }




0
aispCommented:
In the code where you get the count property add the following (I'm assming that count is the name of the variable holding the property)

       String imageArea = "";
        if (count <= 0)
        {
            imageArea="<img src=images/home.gif>";
        }
        else
        {
            for (int i = 1; i <= count; i++)
            {
            imageArea += "<img src=images/help_bar.gif>";
            }
        }
        Response.Write(imageArea);
This will create images at the top of your page in the browser

If you want to place these at a specific place on the page you can do the following, for example. Place
ASP label control on the page <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>.
Then in the above code replace Response.Write(imageArea);  with Label1.Text = imageArea;
Your images will show in the place of the label.
0
aispCommented:
well, use your own image names, of course ... in my example image1=home.gif and image2=help_bar.gif ...
0
kw_uh97Author Commented:
Thanks both of you, both suggestions help me out a bunch. Actually I placed the image(s) in a panel contol to respresent a container of sort.  Here is my code if someone else should browse the topic another day.

if (NumberSmileysDisplayed <= 0)
{
Image vImage = new Image();
vImage.ImageUrl = "images/gsmiley.gif";
cFacePanel.Controls.Add(vImage);
}
else
{
for(int i=1;i<=(NumberSmileysDisplayed);i++)
{
Image vImage = new System.Web.UI.WebControls.Image();
vImage.ImageUrl = "images/bfrown.gif";
cFacePanel.Controls.Add(vImage);
}
}

This was my first time using expert exhange and I am very impressed. I think I have found an invaluable resource here well worth the cost. Thanks Again for all the help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.