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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:42:48+00:00 2026-06-09T14:42:48+00:00

I am receiving a DataTable object from the controller and using that to display

  • 0

I am receiving a DataTable object from the controller and using that to display a table in the view with the following code:

@model System.Data.DataTable 

<table width="65%">
<tr>        

    <th>USERNAME</th>
    <th>ROLE</th>
    <th>ACTIVE</th>
    <th></th>
    <th></th>

</tr>

@foreach(DataRow row in Model.Rows)
{
    <tr>           

        @foreach (DataColumn column in Model.Columns)
        {
            <td>@row[column]</td>   
        }

        <td>@Html.ActionLink("Edit", "Edit", new { id = row[0] })</td>
        <td>@Html.ActionLink("Delete", "Delete",new{id=row[0]})</td>              

    </tr>        
}
</table>

I’d like to add pagination so that the user doesn’t have to scroll down for a long period when the table becomes populated with a lot of data. This is for a basic learning exercise that I’m doing where I’ve hard-coded all of the database SQL calls in the relevant controller action methods. I’m not using an ORM like NHibernate so ideally I’m looking for a solution that just uses the DataTable object on the server side.

Here’s the code from the controller (with the DB specifics removed):

public ActionResult Index()
    {            
        string oradb = "Data Source = XXXXXXXXXXXXXXXXXXX";

        OracleConnection conn = new OracleConnection(oradb);

        conn.Open();

        string sql = " SELECT USER_ROLE_ID, USERNAME, ROLE, ACTIVE_IND FROM LD_USER_ROLE";

        OracleDataAdapter adapter = new OracleDataAdapter(sql, conn);
        DataTable dt = new DataTable();
        adapter.Fill(dt);

        conn.Close();


        return View(dt);            
    }
  • 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-09T14:42:49+00:00Added an answer on June 9, 2026 at 2:42 pm

    In order to solve this I had to rewrite the controller method so that it converted the DataTable into a List of User objects and then I passed this list through to the view. By doing this I was then able to use the WebGrid object which enables easy pagination. The controller code also uses a dataAccess object to encapsulate some of the database info and calls.

    Controller code:

    public ActionResult Index()
        {
            UserRoleDAL udl = new UserRoleDAL();
            DataSet ds = udl.GetData(" SELECT USER_ROLE_ID, USERNAME, ROLE, ACTIVE_IND FROM LD_USER_ROLE");
    
    
            var ZUsers = new List<ZUserRoleModel>();
    
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var dr = ds.Tables[0].Rows[i];
    
    
                    var ZUser = new ZUserRoleModel()
                    {
                        UserRoleId = Convert.ToInt64(dr["USER_ROLE_ID"]),
                        UserName = dr["USERNAME"].ToString(),
                        Role = dr["ROLE"].ToString(),
                        ActiveInd = ActiveBool
                    };
                    ZUsers.Add(ZUser);
                }
            }
    
            return View(ZUsers);
        }
    

    View Code:

    @model IEnumerable<CIMsWebApp.Models.ZUserRoleModel>
    
    
    
    @{  var grid = new WebGrid(Model, canSort: false, canPage: true, rowsPerPage:25); }
    
    
    @grid.GetHtml(
                    tableStyle: "dataGrid", 
                    headerStyle: "header",
                    alternatingRowStyle: "evenRow", 
                    columns: grid.Columns
      (
              grid.Column(header: "UserName", columnName: "UserName"),
              grid.Column(header: "Role ", columnName: "Role"),
              grid.Column(header: "Active", columnName: "ActiveInd"),
              grid.Column(header: "Edit", format: @<text>@Html.ActionLink("Edit", "Edit",  new { id = @item.UserRoleId })</text>),
              grid.Column(header: "Delete", format: @<text>@Html.ActionLink("Delete", "Delete", new { id = @item.UserRoleId })</text>)
      ))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with some code that uses an OleDbConnection to load data from
When receiving data through a socket using recv , I've noticed that, with: char
Am receiving null from json post using jquery. see my code below in order.
After receiving very good correction from fuzzy lollipop, I amended my code to create
I'm receiving errors from Gtk that I can't track down. Every time my mouse
I have the following function in by Data Access Layer but I am receiving
Receiving the following error when doing a simple calendar fetch: Expected response code 200,
Receiving the following upon call to hostContainer.ComposeParts() : System.ComponentModel.Composition.ChangeRejectedException was unhandled Message=The composition remains
When receiving an array from flash, in C, how do I populate that array
I am receiving data from a web service, and some of the strings have

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.