Solved

using a variable to display the number of images

Posted on 2007-03-23
10
236 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
  • 4
  • 4
  • 2
10 Comments
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
It is better to do it on C# side.

0
 

Author Comment

by:kw_uh97
Comment Utility
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
Comment Utility
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
 

Author Comment

by:kw_uh97
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:kw_uh97
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now