0

I am learning .NET for a college project, having an already solid knowledge of PHP. I want to find out how to print out html content in .NET like I would do in PHP.

PHP example:

<?php
    $array = array("foo", "bar", "hello", "world");
    for($i=0; $i<count($array); $i++) {

       echo "<p id=\"$i\">This is paragraph $i.</p>"; 

    }
?>

This is a simple example of what I'm trying to achieve and understand. How would I do the above in ASP.NET?

Thanks for your help.

2 Answers 2

1

Write this on your page

  <%   
  var array = new string[]{"foo", "bar", "hello", "world"};
  Response.ContentType = "text/html";
  for(int i = 0; i < array.Length; i++) 
  {
  Response.Write(string.Format("<p id=\"{0}\">This is paragraph {0}.</p>",i)); 
  }
  %>
Sign up to request clarification or add additional context in comments.

Comments

1

Do the below:

<%
   var array = new string[]{"foo", "bar", "hello", "world"};
   Response.ContentType = "text/html";
   for(int i = 0; i < array.Length; i++) {
      Response.Write(string.Format("<p id=\"{0}\">This is paragraph {0}.</p>",i)); 
   }
%>

1 Comment

Do I put this code inside a Panel? Or where does it go?

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.