Solved

GridViews and ASP

Posted on 2010-09-20
2
662 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
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now