Solved

using a variable to display the number of images

Posted on 2007-03-23
10
243 Views
Last Modified: 2010-04-16
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.
0
Comment
Question by:kw_uh97
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 18779560
It is better to do it on C# side.

0
 

Author Comment

by:kw_uh97
ID: 18779624
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
 
LVL 63

Accepted Solution

by:
Zvonko earned 425 total points
ID: 18779661
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kw_uh97
ID: 18780249
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 18780339
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
 

Author Comment

by:kw_uh97
ID: 18780465
Well I guess you exposed me. I am learning C#; I am a novice. Sorry don't beat me too bad.
0
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 425 total points
ID: 18781011
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
 
LVL 1

Assisted Solution

by:aisp
aisp earned 75 total points
ID: 18782067
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
 
LVL 1

Expert Comment

by:aisp
ID: 18782193
well, use your own image names, of course ... in my example image1=home.gif and image2=help_bar.gif ...
0
 

Author Comment

by:kw_uh97
ID: 18782369
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

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question