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

  • SEARCH
  • Home
  • 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 7757775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:10:49+00:00 2026-06-01T13:10:49+00:00

I keep falling back to procedural programming when displaying data in groups and I

  • 0

I keep falling back to procedural programming when displaying data in groups and I am sure that there must be a better way. Your thoughts?

//Example: Sales by Region

@{
    string _Region = "";
    bool _FirstRecordFlag = false;
    }


    @foreach(DataRow Row in dataset.Tables["MonthlySales"].Rows)
    {
        if(_Region != Row["Region"].ToString())
        {
           if(_FirstRecordFlag)
            {
                @:</fieldset>
                _FirstRecordFlag = true;
            }
            @:<fieldset>
            @:  <legend>@Row["Region"]</legend>
            _Region = Row["Region"].ToString())
        }
            <div>
                Display Sales data here...
            </div>
    }
}
  • 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-06-01T13:10:51+00:00Added an answer on June 1, 2026 at 1:10 pm

    I keep falling back to procedural programming when displaying data in
    groups and I am sure that there must be a better way

    Of course that there is a better way. Since your question is tagged with mvc, you should use a view model and perform all this sort of grouping in the controller to populate your view model which will be passed to the view. The Razor view should then be as dumb as possible – it will only display the information from the view model. Working with DataSets and DataRows in a Razor view is just absolutely the wrong way to approach this problem. Your views will resemble like some horrible spaghetti code.

    So think in terms of how you want to present the information on the view. Based on this thinking you will be able to come up with a view model which will reflect this structure. Then all you have to do in the controller action is to map your domain models (DataSets in your case) to the corresponding view model which will be passed to the view.

    And if this is not an ASP.NET MVC application but a WebMatrix site where you only have the View part, you should still define a view model and have your code-behind part of the razor page map the domain model to the view model which will then be manipulated by the view part of the Razor template.

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

Sidebar

Related Questions

Keep in mind that I'm not looking for a list of current browsers to
I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I'm really falling in love with the whole .Net databinding scheme... but apparently there
I am making a program that reads and stores data from Windows EventLog files
I am trying to do some precise alignment with iTextSharp, but I keep falling
I've been falling in love with jQuery bind. The reason is that it grants
I work on relatively sensitive code that we wouldn't want falling into the wrong
ok so this program keep falling apart at the first if statement and keep
My builds keep failing with the following error Project : error PRJ0002 : Error
I am trying to do this but keep on failing. I have a text

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.