Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6783221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:50:17+00:00 2026-05-26T16:50:17+00:00

Suppose I have to populate an unordered list with data from a Dictionary in

  • 0

Suppose I have to populate an unordered list with data from a Dictionary in a project not using MVC. I’m sure ASP.Net lovers will tell me to populate everything from code-behind.
But… should I?

Via embedded code:

<ul>
<% foreach (KeyValuePair<string, string> item in MyDictonary) { %>
    <li><%= item.Key %>: <strong><%= item.Value %></strong></li>
<% } %>
</ul>

I agree it is not a lot clean, but the alternative is a lot worse as I got to write HTML markup directly from my method:

public void writeMyDictionary() {
    StringBuilder sb = new StringBuilder();
    sb.Append("<ul>");

    foreach (KeyValuePair<string, string> item in MyDictonary) {
        sb.AppendFormat("<li>{0}: <strong>{1}</strong></li>", item.Key, item.Value);
    }

    sb.Append("</ul>");
    MyControl.Text = sb.ToString();
}

So, why should I use code-behind to populate all my controls?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:50:17+00:00Added an answer on May 26, 2026 at 4:50 pm

    For this use case, there is no particular value to doing it in code behind.

    I would rather use the markup version instead of the code behind, as you have posted them, but chances are I would simply go with data binding on a Repeater, as it would be the cleanest solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have 2 different ASP.NET applications in IIS. Also, you have some ASCX
Suppose we have a WPF ComboBox and want to populate it using ObjectDataProvider. <ObjectDataProvider
Suppose I have two .NET DataTables populated as follows, where ID is the primary
Suppose I have an array of dates DateTime[] dt = new DateTime[10]; // populate
Suppose I have a list of a couple of thousand organizations and a user
Let's suppose I have a Winforms app with a Dictionary that looks like this:
Please remember that I am not using any ORM tool. I have just written
i have a simple example of a JList that is getting it's data from
Suppose I have function foo(double * pa) where pa is either populated from [0]
suppose i have one datagridview and datagridview has one DataGridViewComboBoxColumn. i have populate datagridview

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.