Solved

GridViews and ASP

Posted on 2010-09-20
2
667 Views
Last Modified: 2013-11-08
I am trying to implement an ASP .NET MVC 2.0 web app.  I am learning as I go, as usaul.  It is my understanding that I can create a strongly typed View that will contain 2 gridviews.  The appropriate View would then display my strongly typed class containing my two gridviews.  However, I  cannot figure out how to write the code in the View page to display the gridviews that have been passed in.  Am I missing something really easy?  Or am I completely on the wrong path.  Some code I have:

//Controller method that gets the data and creates a ViewModel object:
        public ActionResult Index()
        {
            var approvedRequests = repository.FindApprovedRequests();
            var inProgressRequests = repository.FindInProgressRequests();
           
            GridView approvedGV = new GridView();
            approvedGV.DataSource = approvedRequests;
            approvedGV.DataBind();
            approvedGV.AllowPaging = true;
            approvedGV.AllowSorting = true;

            GridView inProgressGV = new GridView();
            inProgressGV.DataSource = inProgressRequests;
            inProgressGV.DataBind();
            inProgressGV.AllowPaging = true;
            inProgressGV.AllowSorting = true;

            var requestsIndex = new RequestsIndexViewModel(inProgressGV, approvedGV);
            return View(requestsIndex);
        }

//ViewModel object class:
    public class RequestsIndexViewModel
    {
        public GridView InProgressGV { get; private set; }
        public GridView ApprovedGV { get; private set; }

        public RequestsIndexViewModel(GridView inProgressGV, GridView approvedGV)
        {

            InProgressGV = inProgressGV;
            ApprovedGV = approvedGV;
            InProgressGV.Caption = "Requests In Progress";
            ApprovedGV.Caption = "Approved Requests";
        }

    }

//The View
--This is what I am missing--
I do not see how to place the Gridviews created from above onto the view page.  I know it can easily be done with the VS designer.  However, then I have a DataStore in my View code.  This to me doesn't follow MVC conventions/intentions.  That is why I want to create the Gridviews in the model and just pass the final result to the View.

Thanks in advance!

Jason
0
Comment
Question by:jmeek01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
Swapnil Piparia earned 500 total points
ID: 33768659
Hi Jason,

     There are several ways to show data in gridview format however using "ASP.Net GridView" control with MVC would not feasible. The alternate ways are as belows

      1. Using MVCContrib
         http://weblogs.asp.net/shijuvarghese/archive/2008/07/23/asp-net-mvc-grid-view-using-mvccontrib.aspx
      2. Creating reusable user control which generates table format like gridview
          http://stephenwalther.com/blog/archive/2008/06/25/asp-net-mvc-tip-9-create-a-gridview-view-user-control.aspx
          http://www.brightmix.com/blog/asp-net-mvc-gridview/
      3. with using jqGrid (using jQuery)
           http://www.schnieds.com/2010/01/gridview-in-aspnet-mvc.html


Thanks,
NetSwap.
0
 

Author Closing Comment

by:jmeek01
ID: 33788958
Using jqGrid was the best choice for my application.  I struggled to get all the libraries included and properly referenced, but that was more of my inexperience than anything.  I have it up and running pretty much exactly how I want it to work.

Thanks much!

Jason
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question