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 155853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:13:44+00:00 2026-05-11T10:13:44+00:00

I am using web forms, C#, Asp.net. As we all know, in this model

  • 0

I am using web forms, C#, Asp.net. As we all know, in this model UI and business logic are often mixed in. How do I separate these effectively?

The example I would like to use is: I have a GridView and a DataTable (GridView binds to the DataTable and DataTable is fed from the stored procedure).

I would like the GridView (UI) and DataTable (business logic) to be decoupled.

Is it worth it to write an wrapper for DataTable? Are there practical patterns that have been proved and tested that you could recommend to be followed?

If someone with experience could shed some light, that would be awesome. And, as a final note I would like to say that ASP MVC is not an option right now, so don’t recommend it.

My database access layer returns a DataTable. Note that I HAVE to use this database layer as this is a company policy.

  • 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. 2026-05-11T10:13:45+00:00Added an answer on May 11, 2026 at 10:13 am

    I went through this recently while decoupling much the same thing from our UI layer.

    You can see my progress here and here.

    In my opinion, A DataTable does not represent business logic. Specifically, it’s data pulled directly from the database. Business logic turns that data into a truly useful business object.

    The first step, then, is to decouple the DataTable from the Business object.

    You can do that by creating objects and List<object> that make up DataTables and Collections of DataTables, and then you can make a ListView that displays those Objects. I cover the latter steps in the links I posted above. And the former steps are as easy as the following:

    1. Create a class that will represent your object.
    2. iterate through your DataTable (or DataSet, or however you retrieve the data) and shove those fields into properties of that object (or that List<T>);
    3. return that List to the Gridview or ListView to display.

    This way your ListView or Gridview won’t be tightly coupled to the method that you are retrieving your data. What happens if you decide to get your data from a JSON query or a XML file later on? Then you’d have to build this into there.

    Step 1 – Getting Data From Database

    There are multiple methods to get data from a database, there’s no way I can go through all of them here. I assume that you already know how to retrieve data from a database, and if you don’t, there are quite a few links to follow. Let’s pretend you’ve connected to the database, and are using an SQLDataReader to retrieve data. We’ll pick up there.

    Class Diagram

    Foo ---- id Name Description 

    And here’s the method:

     private void FillDefault(SqlDataReader reader, Foos foo)         {             try             {                 foo.id = Convert.ToInt32(reader[Foo.Properties.ID]);                 foo.Name = reader[Foo.Properties.NAME].ToString();                                                    if (!string.IsNullOrEmpty(                 reader[Foo.Properties.DESCRIPTION].ToString()))                  foo.Description =                   reader[Foo.Properties.DESCRIPTION].ToString();              else foo.Description = string.Empty;             }             catch (Exception ex)             {                throw new Exception(                string.Format("Invalid Query.                 Column '{0}' does not exist in SqlDataReader.",                 ex.Message));             }         } 

    Once that happens, you can return a list by going through that process in a while loop that targets the SQLDataReader.Read() function.

    Once you do that, let’s pretend that your Foo being returned is a List. If you do that, and follow the first link I gave above, you can replace Dictionary<TKey, TValue> with List<T> and achieve the same result (with minor differences). The Properties class just contains the column names in the database, so you have one place to change them (in case you were wondering).

    DataTable – Update Based on Comment

    You can always insert an intermediate object. In this instance, I’d insert a Business Layer between the DataTable and the UI, and I’ve discussed what I’d do above. But a DataTable is not a business object; it is a visual representation of a database. You can’t transport that to the UI layer and call it de-coupled. They say you have to use a DataTable, do they say that you have to transport that DataTable to the UI? I can’t imagine they would. If you do, then you’ll never be de-coupled. You’ll always need an intermediate object in between the DataTable and the UI layer.

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

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've done this in the past with an attached behavior,… May 12, 2026 at 12:30 am
  • Editorial Team
    Editorial Team added an answer char *seq=(char *)malloc((strlen(first)+1)*sizeof(char)); You are allocating memory for a string… May 12, 2026 at 12:30 am
  • Editorial Team
    Editorial Team added an answer If you are using Visual Studio, you should be able… May 12, 2026 at 12:30 am

Related Questions

We are using C#, ASP.NET & WCF. I am trying to send form data
I'm working on a web application (with ASP.NET 2.0 (C#) and jQuery) In my
We are about to embark on a large enterprise application. I am seriously considering
I am working on a software development project that uses code written primarily in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.