Click here to Skip to main content
11,709,844 members (50,783 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript HTML , +
I created a c# mvc app over a year ago where I had a dataset of names and pictures and my app creating a new li for every person on the list when the page loaded.

<ul id="People-List">
    @foreach (var people in Model)
        <li class="resize">
              <br />    
              <br />
              <img  alt="Image"src="/@Person.PicturePath" /></a> 
              <br />

I want to make something similar in C# webforms using what I imagine would be C# and javascript.
I have been struggling to add new list items with Javascript and I could do with some advise on the best way to do this, the program would load a local database of people, put them into a dataset then pass the data to the front end where they get added to a javascript version of the code above, creating the html list depending on the data inside it.

I originally wrote this code, but I want to know if im doing it the right way since i will want to add buttons and a number of variables inside each of the list items
<ul id="nav" >  
              <script type="text/javascript">
                      a = new Array("pub 1", "pub 2", "pub 3");
                      for (var i = 0; i < a.length; i++)
                          document.write("<li>" + a[i]  + "</li> ");                      
Posted 9-Jan-13 6:06am
Edited 9-Jan-13 6:13am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you have having trouble with binding try


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 524
1 OriginalGriff 250
2 Peter Leow 229
3 Maciej Los 185
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,037
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100