Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GridViews and ASP

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

722 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