Solved

GridViews and ASP

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 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