Convert PHP script to C# or Javascript

The attached code snippet happens on load of the web page. Can anyone tell me how to convert it to Javascript or C#? Bascially, what I have done is loaded some list items in an array. Then, based on the current page, the HTML is created when the page loads.
// maybe you need to add the directory name(s) too
      $items = array(
          array("link"=>"php.html", "label"=>"PHP scripts"),
          array("link"=>"tut.html", "label"=>"Tutorial"),
          array("link"=>"css.html", "label"=>"CSS template"),
          array("link"=>"code.html", "label"=>"Code examples"));
           
      $menu = '';
      foreach ($items as $val) {
          if  ($_SERVER['SCRIPT_NAME'] == $val['link']) {
          $menu .= '<li><span>' .$val['label'].'</span></li>';
 
	  } else {
	  $menu .= '<li><a href="'.$val['link'].'" >'.$val	   ['label'].'</a></li>';
	  }
      }
      echo $menu;

Open in new window

LVL 3
computerstreberAsked:
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.

Ryan ChongCommented:
I saw your pages are in .html, so I decided to use javascript to generate the menu.
<script language="javascript">
	//Ver 1.0
	function getFileName(fpath, removeQueryingString, delimiter) {
		if (fpath==null) fpath = window.location.href;
		if (delimiter==null) delimiter = "/";
		var tmp = fpath;
		if (tmp.lastIndexOf("?") > -1) {
			tmp = tmp.substring(0,tmp.lastIndexOf("?"));		
		}
		tmp = tmp.substring(tmp.lastIndexOf(delimiter)+1);
		if (removeQueryingString != null) {
			if (removeQueryingString) {
				var tmpArr = tmp.split("?");
				tmp = tmpArr[0];
			}
		}
		return tmp;
	}
 
	function generateMenu() {
		var arrlink = new Array(3);
		var arrlabel = new Array(3);
		arrlink[0] = "php.html";
		arrlabel[0] = "PHP scripts";
		arrlink[1] = "tut.html";
		arrlabel[1] = "Tutorial";
		arrlink[2] = "css.html";
		arrlabel[2] = "CSS template";
		arrlink[3] = "code.html";
		arrlabel[3] = "Code examples";
		
		var menu = "";
		for (var i=0;i<arrlink.length;i++) {
			if  (getFileName() == arrlink[i]) {
				menu += "<li><span>" + arrlabel[i] + "</span></li>";
			} else {
				menu += "<li><a href='" + arrlink[i] + "'><span>" + arrlabel[i] + "</span></a></li>";
			}
		}
		return menu;
	}
	
	document.write(generateMenu());
</script>

Open in new window

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
naspinskiCommented:
asp.net/c#
<!--asp.net-->
<asp:DropDownList ID="ddl" runat="server" />
 
// C# -- put this in your page_load
if (!IsPostBack)
{
    Dictionary<string, string> items = new Dictionary<string, string>();
    items.Add("php.html", "PHP scripts");
    items.Add("tut.html", "Tutorial");
    items.Add("css.html", "CSS template");
    items.Add("code.html", "Code examples");
 
    foreach (var item in items)
        ddl.Items.Add(new ListItem(item.Value, item.Key));
}

Open in new window

0
naspinskiCommented:
actually, I made that more complicated than I needed to, keep the same asp.net of:

<asp:DropDownList ID="ddl" runat="server" />

and put this in your codebehind:
if(!IsPostBack)
{
    ddl.Items.Add(new ListItem("php.html", "PHP scripts"));
    ddl.Items.Add(new ListItem("tut.html", "Tutorial"));
    ddl.Items.Add(new ListItem("css.html", "CSS template"));
    ddl.Items.Add(new ListItem("code.html", "Code examples"));
}

Open in new window

0
computerstreberAuthor Commented:
both of these were awesome examples. However, I found the javascript to render much better.
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
JavaScript

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.