Bind C# List of object data with HTML without using ASP.Net control in ASP.Net

In ASP.Net we always use so may ASP.Net controls . But we also know ASP.Net controls have ViewState , so we should ignore using ASP.Net controls as much as possible to reduce the Load time of DOM .

In my example , I will show how we can bind and show the data to HTML without using ASP.Net Control in ASP.Net.

I have a List of a custom object like below :

protected List<voNote> notes = new List<voNote>();

This is a list of a ViewModel . and the ViewModel of my example is like below :::

public class voNote
        public string Note { get; set; }

        public DateTime Date { get; set; }

        public string NoteCreatedBy { get; set; }

        public string TicketUrgency { get; set; }

Let, We have populated the List from Database Server . Now we have to show/Bind the Data to the UI .

So my markup code will be just simple like below :

        foreach (voNote note in notes)
            <hr class="NoteBorder" />
            <div><%=note.Date %> | <%=note.NoteCreatedBy %> | <%= note.TicketUrgency %></div>
            <div class="NoteDiv"><%=note.Note %></div>

So , its done 🙂