Click here to Skip to main content
15,893,594 members

C# Dataset to Html List on pageload

Phoenix234 asked:

Open original thread
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.

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

    }
</ul>


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
HTML
<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> ");                      
                      }
                    
                </script>
          </ul>

Advice?
Tags: C#, Javascript, HTML, WebForms, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900