Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GridViews and ASP

Posted on 2010-09-20
2
Medium Priority
?
675 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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.…
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 Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.

972 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